Python Tutorial Python Advanced Python References Python Libraries

Python cmath - rect() Function



The Python cmath.rect() function is used to convert a complex number from polar coordinates to rectangular coordinates. The function returns (x, y) which is a rectangular representation of (r, θ). rect(r, θ) is equivalent to (r*cos(θ), r*sin(θ)) = (x, y).

Syntax

cmath.rect(r, θ)

Parameters

r Required. Specify the modulus of a complex number.
θ Required. Specify the phase of a complex number.

Return Value

Returns the representation of a complex number in rectangular coordinates.

Example:

In the example below, rect() function is used to convert a given complex number from polar coordinates to rectangular coordinates.

import cmath

r = 5
theta = cmath.pi/3

print(cmath.rect(r, theta))

The output of the above code will be:

(2.5000000000000004+4.330127018922193j)

❮ Python cMath Module