math.sin incorrect result

空扰寡人 提交于 2019-12-04 22:21:19

问题


>>> import math
>>> math.sin(68)
-0.897927680689

But

sin(68) = 0.927 (3 decimal places)

Any ideas about why I am getting this result?
Thanks.


回答1:


>>> import math
>>> print math.sin.__doc__
sin(x)

Return the sine of x (measured in radians).

math.sin expects its argument to be in radians, not degrees, so:

>>> import math
>>> print math.sin(math.radians(68))
0.927183854567



回答2:


by default angle in Python is calculated in radians. So, you can try to multiply the angle ( degrees ) by 0.01745 - to convert it to degrees and input the values. print(math.sin(60*0.01745)) 0.8659266112878228



来源:https://stackoverflow.com/questions/1237085/math-sin-incorrect-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!