Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

math.sin incorrect result

>>> 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.

like image 665
Strigoides Avatar asked Aug 06 '09 05:08

Strigoides


2 Answers

>>> 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
like image 177
mhawke Avatar answered Nov 12 '22 04:11

mhawke


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

like image 44
Deepak Avatar answered Nov 12 '22 05:11

Deepak