user6240030
user6240030

Reputation: 41

sin equation in python keeps returning the wrong answer

I think I have a buggy version of python, because I am getting the wrong result. If you type this: sin(degrees(39))*41/28 directly into google, you will get the value 0.92150485832. This is the correct value for the given equation.

When I try to execute this in python however, I get the value -1.11258224646.

The code I used:

number= float(sin(degrees(39))*41/28)
print number

I also tried the following code (removed degrees surrounding the 39), which returns the value 1.41127181563.

number= float(sin(39)*41/28)
print number

Just for the kicks, I also tried the code like this:

number= float(sin(radians(39))*41/28)
print number

This code returned the answer 0.921504858323, which would be the correct answer for the first equation

That shouldn't be possible as 39 in radians is 0.680678408. And using that number in the equation: (sin(0.680678408)*41)/28 we get 0.017395421, not 0.921504858323.

Can someone please explain what's going on here. I'm lost here.

Upvotes: 3

Views: 2010

Answers (2)

Rahul Verma
Rahul Verma

Reputation: 3176

Use this

    >> math.sin(math.radians(39))*41/28
    0.9215048583229761

Upvotes: 0

simon
simon

Reputation: 1405

The explanation is in difference of interpretation of words "degrees" and "radians" between google and python.

  1. In python these 2 are functions for converting from one unit to another:

    • math.degrees(x) - Convert angle x from radians to degrees.
    • math.radians(x) - Convert angle x from degrees to radians.

To evaluate "float(sin(radians(39))*41/28)" statement python converts 39 degrees angle into radians (0.680678) then computing sin(x) which returns the sine of x radians, so we will get sin(39 degree)*41/28.

  1. Google uses 2 words for clarification of unit and not for conversion. to evaluate "sin(degrees(39))*41/28" google understands it as "sin(39 degree)*41/28", so it is not converting units between radians and degrees. It is just calculation sine of 39 degree.

Upvotes: 3

Related Questions