gir*_*ipp 3 c python trigonometry
我用Python制作了这段代码
def hitsin(a):
a = a*57.3
return math.sin(a)
Run Code Online (Sandbox Code Playgroud)
所以每当我把hitsin(x)x转换为弧度.当我把hitsin(90)的答案不是1或者任何数字接近1而是负数(它是-0.9971392129043587)时,我很困惑.我做错了吗?
ps:我也尝试在C中编写相同类型的代码
#include <stdio.h>
#include <math.h>
int main(){
float degree;
float result;
degree = 90;
degree = degree*57.3;
result = cos(result);
printf("%f",result);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
但答案是一样的.
真诚的,你的吉里
Sve*_*ach 13
你应该除以180/pi,而不是乘.在Python中,您还可以使用math.radians()从度到弧度的转换:
def hitsin(a):
return math.sin(math.radians(a))
hitsin(90)
# 1.0
Run Code Online (Sandbox Code Playgroud)
此外,我怀疑C代码提供与Python代码相同的结果,因为它使用cos()而不是sin().
| 归档时间: |
|
| 查看次数: |
2372 次 |
| 最近记录: |