math.cos(x) 回傳 x(弧度)的余弦值,範圍在 [-1, 1] 之間。
import math
math.cos(x)
#!/usr/bin/python
import math
print("cos(3) :", math.cos(3)) # -0.9899924966
print("cos(-3) :", math.cos(-3)) # -0.9899924966 (偶函數)
print("cos(0) :", math.cos(0)) # 1.0
print("cos(math.pi) :", math.cos(math.pi)) # -1.0
print("cos(2*math.pi):", math.cos(2*math.pi)) # 1.0
cos(3) : -0.9899924966
cos(-3) : -0.9899924966
cos(0) : 1.0
cos(math.pi) : -1.0
cos(2*math.pi): 1.0
若輸入為角度,需先轉弧度:
deg = 60
rad = math.radians(deg)
print(math.cos(rad)) # 0.5
x = A*cos(ωt + φ)。