Math.sin incorrect result

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

But

 sin(68) = 0.927 (3 decimal places) 

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

+6
python math trigonometry sin
source share
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 
+26
source share

Quote from stack overflow answer for question
fooobar.com/questions/856825 / ... :

This is because you use degrees and trigonometric functions expect radians as input: sin (radians)

Description for sin:

 sin(x) Return the sine of x (measured in radians). 

In Python, you can convert degrees to radians using the math.radians function.

So, if you do this with your input:

 >>> math.sin(math.radians(35)) * 15 + 9 17.60364654526569 

it gives the same result as your calculator.

So itโ€™s true, itโ€™s true that โ€œ math.sin the wrong result โ€ is incorrect,
math.sin result math.sin correct , but just used in another format / style (radians) to enter the one you want to use (in degrees).

Therefore, you just need to convert radians to degrees in
make the result as you want (maybe like your calculator).

+2
source share

All Articles