• Post Reply Bookmark Topic Watch Topic
  • New Topic

Math functions cosine problems  RSS feed

 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm just testing some math functions. I'm comparing the results to what I get from my calculator and I'm getting different results. for example:
on my calculator cos(89.97) = 0.000523598751674
but in java I get cos( 89.97) = -0.4210561210198809
so I checked google with this query and google also says its -0.421056121
Why would my calculator be wrong?
Then I thought about it logically, if I was trying to solve a right triangle for the adjacent side and knew my hypotenuse to be "c" such that "c" is any positive number above 0, and
cos(89.97) = adjacent/c, then the adjacent = cos(89.97) * c.
adjacent can't be negative so google must be wrong, same goes for java.

so... what did I do wrong?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

so... what did I do wrong?


Your calculator is probably configured to use degrees. Java, (and the google site you used) are configured to use radians.

Henry
 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I make java use degrees to calculate sine?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by A. Wolf:
How can I make java use degrees to calculate sine?


The Math class provides methods to convert to radians and back to degress.

Henry
 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite right you are and you can do it yourself by multiplying by Math.PI/180 for radians or the inverse to get degrees. Either way, I've looked at the documentation too although your last post seems to suggest otherwise.

here's what I've tried so far with little success



Upon searching for articles elsewhere people have suggested to use radians entirely instead of degrees. I feel betrayed that we were drilled in degrees during math class and barely focused on radians even though the important things in the world ( like java ) uses them.

--edited to be less rude.
[ June 26, 2005: Message edited by: A. Wolf ]
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try...



Degrees and Radians are measurement of angles (gradians is the third measurement). The cosine() method takes radians. If you have degrees, it must be coverted prior to calling the cosine method.

BTW, I don't think I was implying anything... certainly didn't attempt to sound condesending.

Henry
[ June 26, 2005: Message edited by: Henry Wong ]
 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
found the solution.
Dont use degrees.
its that simple.
Pretend you're using degrees if you're not used to it, but know that you're using radians.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!