{"id":12550,"date":"2021-09-30T17:30:00","date_gmt":"2021-09-30T12:00:00","guid":{"rendered":"https:\/\/python-programs.com\/?p=12550"},"modified":"2021-11-22T18:33:33","modified_gmt":"2021-11-22T13:03:33","slug":"python-program-to-find-magnitude-of-a-complex-number","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-magnitude-of-a-complex-number\/","title":{"rendered":"Python Program to Find Magnitude of a Complex Number"},"content":{"rendered":"

Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners<\/a> tutorial.<\/p>\n

Using a simple snippet, we can calculate the Magnitude of a Complex Number in Python.
\nLet us begin by learning the fundamentals of complex numbers in Python.
\nFirst, let’s look at how to initialize or declare a complex number in Python.<\/p>\n

Complex Number:<\/strong>
\nBy setting a variable to a + bi, we can generate a complex number. In this case, a and b are real numbers.<\/p>\n

4+11i<\/p><\/blockquote>\n

In the above example, the real part(a) is 4 and the imaginary part(b) is 11.
\nThe complex([real][,imaginary]) method can also be used to generate a complex number. Its parameters are the real and imaginary parts, respectively.
\nIf a parameter is not specified, the complex number’s corresponding portion is set to the default value. The default setting is 0.<\/p>\n

Example:<\/strong><\/p>\n

cmplxnumber = complex(9,2)<\/p><\/blockquote>\n

In this application, we will utilize the abs()<\/strong> function to determine the magnitude of a complex number. The method abs() only accepts one argument.
\nThe following is an example of an argument:
\n1. The Float Number
\n2. Complex Number
\n3. Integer
\nIf the number is an integer or a floating-point, abs(number) returns<\/p>\n

1. Modulus of the number.
\n2. The magnitude of the number if it is complex.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given real part = 12\r\nGiven imaginary part = 16<\/pre>\n

Output:<\/strong><\/p>\n

The magnitude of the complex number (12+16j) = 20.0<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given real part = 11\r\nGiven imaginary part = 47<\/pre>\n

Output:<\/strong><\/p>\n

The magnitude of the complex number (11+47j) = 48.27007354458868<\/pre>\n

Python Program to Find Magnitude of a Complex Number<\/h2>\n

Below are the ways to find the magnitude of a complex number in Python.<\/p>\n