• 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
  • VBA
  • 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 Sort Two Lists Together
  • 2.  How to Check If File is Empty with Python
  • 3.  Break Out of Function in Python with return Statement
  • 4.  How to Check if Set is Empty in Python
  • 5.  Using Python to Capitalize Every Other Letter of String
  • 6.  Get Size of File in Python with os.path.getsize() Function
  • 7.  Using Python to Read Random Line from File
  • 8.  Get Name of Function in Python
  • 9.  How to Get the Size of a List in Python Using len() Function
  • 10.  Divide Each Element in List by Scalar Value with 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

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

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 © 2022 · The Programming Expert · About · Privacy Policy