三、使用math.cos()和math.tan()函数 与sin()函数相似,math模块也提供了cos()和tan()函数用于计算余弦值和正切值。 import math 计算余弦值 cos_value = math.cos(angle_in_radians) print(f"The cosine of {angle_in_degrees} degrees is: {cos_value}") 计算正切值 tan_value = math.tan(angle_in...
sin_value = math.sin(angle_in_radians) cos_value = math.cos(angle_in_radians) tan_value = math.tan(angle_in_radians) return sin_value, cos_value, tan_value 使用numpy库 def trig_functions_with_numpy(angle_in_degrees): angle_in_radians = np.deg2rad(angle_in_degrees) sin_value = np....
sin(x):计算给定角度/弧度x的正弦值。cos(x):计算给定角度/弧度x的余弦值。tan(x):计算给定角度/弧度x的正切值。asin(x):计算给定值x的反正弦值,返回角度/弧度。acos(x):计算给定值x的反余弦值,返回角度/弧度。atan(x):计算给定值x的反正切值,返回角度/弧度。2.通过math库进行三角函数计算 使用...
1. 正弦函数(sin):正弦函数用于计算给定角度的正弦值。它的语法如下:```pythonmath.sin(x)```其中`x`是角度的弧度值。如果您想使用角度而不是弧度,可以将角度转换为弧度,如下:```pythondegrees = 45radians = math.radians(degrees)sin_value = math.sin(radians)```2. 余弦函数(cos):余弦函数用...
1. sin(x) - 正弦函数:import mathangle = 45 # 角度(单位:度)result = math.sin(math.radians(angle)) # 将角度转换为弧度print(result)2. cos(x) - 余弦函数:pythonCopy codeimport mathangle = 60 # 角度(单位:度)result = math.cos(math.radians(angle)) # 将角度转换为弧度print(...
= {tan(radians)}") # 输出正切值在上述代码中,我们首先定义了一个将角度转换为弧度的函数degrees_to_radians,然后定义了三个函数sin、cos和tan,分别用于计算正弦、余弦和正切值。最后,我们使用一个测试角度45度作为输入,并打印出相应的正弦、余弦和正切值。运行结果如上图。总结 Python中的math模块提供了丰...
输出 sin(30°) 的值# 余弦函数 cos(x),其中 x 为角度(弧度)importmathx=60# 角度y=math.cos...
例如,我们可以使用math库中的radians函数将角度转换为弧度,然后再调用sin、cos、tan等函数进行计算。下面是一个简单的示例:angle_degrees = 45angle_radians = math.radians(angle_degrees)sin_value = math.sin(angle_radians)print(sin_value)特殊情况的处理 有时候,我们可能需要处理一些特殊情况,例如输入角度不...
exec(math.pi/6, math.sin, "求sin(30度)") # sin(30度)= 1/2 exec(0.5, math.asin, "求asin(30度)") # asin(1/2) = 30度 print(math.degrees(math.asin(0.5))) # 30度 exec(math.pi/3, math.cos, "求cos(60度)") # cos(60度)= 1/2 ...
–`math.cos(x)`: 返回x的余弦值。 –`math.tan(x)`: 返回x的正切值。 –`math.asin(x)`: 返回x的反正弦值。 –`math.acos(x)`: 返回x的反余弦值。 –`math.atan(x)`: 返回x的反正切值。 –`math.degrees(x)`: 将弧度转换为角度。