1.

How is a complex number in Python represented in terms of polar coordinates?

Answer»

Complex number z=x+yj is a Cartesian (also CALLED rectangular) representation. It is internally REPRESENTED in polar coordinates with its modulus r (as returned by built-in abs() function) and the phase angle θ (pronounced as theta) which is counter clockwise angle in radians, between the x axis and LINE joining x with the origin. Following diagram illustrates polar representation of complex number:

FUNCTIONS in cmath module allow conversion of Cartesian representation to polar representation and vice versa.

polar() : This function returns polar representation of a Cartesian notation of complex number. The return value is a tuple consisting of modulus and phase.

>>> IMPORT cmath >>> a=2+4j >>> cmath.polar(a) (4.47213595499958, 1.1071487177940904)

Note that the modulus is returned by abs() function

>>> abs(a) 4.47213595499958

phase(): This function returns counter clockwise angle between x axis and segment joining a with origin. The angle is represented in radians and is between π and -π

>>> cmath.phase(a) 1.1071487177940904

rect(): This function returns Cartesian representation of complex number represented in polar form i.e. in modulus and phase

>>> cmath.rect(4.47213595499958, 1.1071487177940904) (2.0000000000000004+4j)


Discussion

No Comment Found