Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

real and imaginary part of a complex number in polar form

I am a bit confused about the proper way to deal with complex numbers in polar form and the way to separate its real and imaginary part.

Notice that I am expecting as real part the radius, as imaginary part the angle.

The inbuilt re and im functions get always the real and imaginary part of the Cartesian representation of the complex number.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here an example

from sympy import I, pi, re, im, exp, sqrt

# complex num in Cartesian form
z = -4 + I*4
print(re(z), im(z))
# 4 -4

# complex num in polar form
z = 4* sqrt(2) * exp(I * pi * 3/4)
print(re(z), im(z))
# 4 -4  but expacting 4*sqrt(2), pi*3/4

What is the most SymPytonic way to deal with such problem?

>Solution :

Maybe you are looking for Abs and arg functions?

z = -4 + I*4
print(Abs(z), arg(z))
# 4*sqrt(2) 3*pi/4

z = 4* sqrt(2) * exp(I * pi * 3/4)
print(Abs(z), arg(z))
# 4*sqrt(2) 3*pi/4
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading