📜  Python| math.sin()函数

📅  最后修改于: 2022-05-13 01:54:53.330000             🧑  作者: Mango

Python| math.sin()函数

在Python中,数学模块包含许多数学运算,可以使用该模块轻松执行。 math.sin()函数返回作为参数传递的值的正弦值。此函数中传递的值应以弧度为单位。

代码#1:

# Python code to demonstrate the working of sin()
     
# importing "math" for mathematical operations 
import math 
    
a = math.pi / 6
     
# returning the value of sine of pi / 6 
print ("The value of sine of pi / 6 is : ", end ="") 
print (math.sin(a)) 
输出:
The value of sine of pi/6 is : 0.49999999999999994


代码#2:

# Python program showing 
# Graphical representation of 
# sin() function 
import math
import matplotlib.pyplot as plt 
  
in_array = [-3.14159265, -2.57039399, -0.28559933,
            0.28559933, 2.57039399,  3.14159265]
  
out_array = []
  
for i in range(len(in_array)):
    out_array.append(math.sin(in_array[i]))
    i += 1
  
   
print("in_array : ", in_array) 
print("\nout_array : ", out_array) 
  
# red for numpy.sin() 
plt.plot(in_array, out_array, color = 'red', marker = "o") 
plt.title("math.sin()") 
plt.xlabel("X") 
plt.ylabel("Y") 
plt.show() 
输出: