Python – cmath.sin()函数
cmath是用于复数数学的Python内置模块。 cmath 模块有一个方法 sin(),它返回传递给它的复数的正弦值。
Syntax: cmath.sin(Z)
Parameter: It requires only one parameter i.e the number for which sine needs to be calculated.
Return: Returns a complex number that is the sine of the number passed.
示例 1:
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.sin(5 + 3j))
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.sin(1))
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.sin())
输出:
(-9.654125476854839+2.841692295606352j)
示例 2:在此示例中传递了实数,但返回的结果仍然是复数。
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.sin(1))
输出:
(0.8414709848078965+0j)
示例 3:在此示例中,在这种情况下不传递任何参数,TypeError 将被抛出
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.sin())
输出:
TypeError: sin() takes exactly one argument (0 given)