VOOZH about

URL: https://www.geeksforgeeks.org/python/finding-magnitude-of-a-complex-number-in-python/

⇱ Finding Magnitude of a Complex Number in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Finding Magnitude of a Complex Number in Python

Last Updated : 23 Jul, 2025

Complex numbers are an essential part of mathematics and engineering, often encountered in various fields such as signal processing, control systems, and physics. The magnitude of a complex number is a measure of its distance from the origin in the complex plane. In Python, there are several ways to calculate the magnitude of a complex number.

Syntax :

Z= a+jb

Magnitude = √a2 + b2

Finding Magnitude of a Complex Number in Python

Below, are the ways to Finding Magnitude of a Complex Number in Python.

Manually Calculating Magnitude

We can manually calculate the magnitude by taking the square root of the sum of the squares of the real and imaginary parts.


Output
Manually calculated magnitude: 5.0

Magnitude of a Complex Number Using abs() Function

In this example, the abs() function in Python can be used to find the magnitude of a complex number. The abs() function returns the absolute value of a number, and for complex numbers, it calculates the magnitude.


Output
Magnitude using abs(): 5.0

Magnitude of a Complex Number Using cmath Module

In this example, the cmath module in Python provides mathematical functions for complex numbers. The cmath module's abs() function can be used to find the magnitude.


Output
Magnitude using cmath: 5.0

Magnitude of a Complex Number Using pow() Method

In this example, The math module in Python provides a sqrt() function, which can be combined with the pow() function to find the magnitude.


Output
Magnitude using pow() module: 5.0

Conclusion

In Conclusion , the above methods offer different ways to calculate the magnitude of a complex number in Python. Choose the one that fits your preference or the requirements of your specific application. Understanding these methods can be beneficial in solving problems related to complex numbers in various scientific and engineering domains.

Comment