complex phase python 1

complex phase python

# calc the magnitude (abs) and the phase of a complex number 
from cmath import phase # No need to import abs()

c = 1 + 2j
print(abs(c)) # Should print 2.23606797749979
print(phase(c)) # Should print 1.1071487177940904

Here is what the above code is Doing:
1. Importing the phase() function from the cmath module.
2. Creating a complex number c.
3. Printing the magnitude of c.
4. Printing the phase of c.

Similar Posts