• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Find Magnitude of Complex Number in Python

Find Magnitude of Complex Number in Python

May 5, 2022 Leave a Comment

To find the magnitude of a complex number in Python, you can create a complex object and take the absolute value of that object.

c = complex(5,7) #represents the complex number 5 + 7i

magnitude = abs(c)

print(magnitude)

#Output:
8.602325267042627

One of the reasons why Python is so awesome is that we can perform a diverse set of calculations very easily. One calculation is to be able to find the magnitude of a complex number.

Complex numbers are made up of two parts. The first part is the “real” part, and the second part is the “imaginary” part.

The magnitude of a complex number is the length of the vector created by a coordinates from (0,0) by a complex number in the complex plane.

We can easily get the magnitude of a complex number with Python by utilizing the Python complex() function and Python abs() function.

Below are some examples of how you can find the magnitude of complex numbers in your Python code.

a = complex(5,7) #represents the complex number 5+7j
b = complex(2,-3) #represents the complex number 2-3j
c = complex("10-5j") #represents the complex number 10-5j
d = complex("4j") #represents the complex number 4j

print(abs(a))
print(abs(b))
print(abs(c))
print(abs(d))

#Output:
8.602325267042627
3.605551275463989
11.180339887498949
4.0

Hopefully this article has been useful for you to learn how to calculate the magnitude of a complex number in Python.

Other Articles You'll Also Like:

  • 1.  Using Python to Increment Dictionary Value
  • 2.  Python Add Months to Datetime Variable Using relativedelta() Function
  • 3.  Get Tomorrow’s Date as Datetime in Python
  • 4.  Python cube root – Find Cube Root of Number With math.pow() Function
  • 5.  Python Prime Factorization – Find Prime Factors of Number
  • 6.  Euclidean Algorithm and Extended Euclidean Algorithm in Python
  • 7.  pandas T Function – Transposing DataFrames with pandas
  • 8.  pandas max – Find Maximum Value of Series or DataFrame
  • 9.  Remove Empty Strings from List in Python
  • 10.  Check if Number is Between Two Numbers Using Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy