Python's Trigonmetric Function Return Unexpected Values
import math print 'python calculator' print 'calc or eval' while 0 == 0: check = raw_input() #(experimental evaluation or traditional calculator) if check == 'eval':
Solution 1:
You don't want o convert the return value of sin()
to degrees -- the return value isn't an angle. You instead want to convert the argument to radians, since math.sin()
expects radians:
>>> math.sin(math.radians(90))
1.0
Solution 2:
Python's sin and cos take radians not degrees. You can convert using the math.radians function. Basically, you are using the wrong units.
Solution 3:
Most math functions, including Python's math functions, use radians as the measure for trigonometric routines.
Compare:
>>>math.sin(90)
0.8939966636005579
>>>math.sin(3.1415926535)
8.979318433952318e-11
>>>math.cos(180)
-0.5984600690578581
>>>math.cos(2*3.1415926535)
1.0
>>>
Solution 4:
You are using degrees, but the sin
function expects radians (see the documentation: help(math.sin)
). 90° is 𝜋/2.
>>> import math
>>> math.sin(math.pi/2)
1.0
>>> math.radians(90) - math.pi/20.0
Solution 5:
Convert your input from degrees to radians before calling math.sin
Post a Comment for "Python's Trigonmetric Function Return Unexpected Values"