Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math.cos() gives wrong result

According to Wolfram Mathematica: cos(50) = 0.6427876096865394;

But this code in Java:

    System.out.println(Math.cos(50)); 

gives 0.9649660284921133.

What is wrong with java.lang.Math?

like image 703
z3on Avatar asked Oct 19 '12 14:10

z3on


People also ask

Does Math cos return radians or degrees?

The Math. cos() function returns the cosine of a number in radians.

How do you evaluate a COS function in Python?

In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math. cos() function returns the cosine of value passed as argument. The value passed in this function should be in radians.

Does Math cos use radians?

The cosine is equal to the ratio of the side adjacent to the angle and the hypotenuse of the right-angled triangle they define. The angle must be measured in radians.

What is Math cos in JavaScript?

The Math. cos() method is used to return the cosine of a number. The Math. cos() method returns a numeric value between -1 and 1, which represents the cosine of the angle given in radians.


1 Answers

Math.cos() expects the parameter to be in radians. This will return the result you need:

Math.cos(Math.toRadians(50)); 
like image 146
Dan D. Avatar answered Sep 23 '22 21:09

Dan D.