Python – cmath.rect() 方法
cmath是一个Python内置模块,用于复数数学。 cmath 模块有一个方法 rect() 用于将极坐标转换为矩形形式。
Syntax: cmath.rect(r, phi)
Parameter: It take two arguments. First argument r, denotes the modulus of the complex number and the second argument denotes the phase. Both arguments are required. None is optional.
Return: Returns a complex number Z whose modulus is r and phase is phi.
注意: r * (math.cos(phi) + math.sin(phi)*1j) 等价于这个方法。
示例 1:
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.rect(3,10))
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.rect(0,1))
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.rect(1,0))
输出:
(-2.517214587229357-1.6320633326681093j)
示例 2:在此示例中,模数取为零。
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.rect(0,1))
输出:
0j
示例 3:在此示例中,相位为零
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.rect(1,0))
输出:
(1+0j)