| | |
The problem with using Java's maths.cos()
![]() |
P.S. I've done a small test and Math.cos(x) yields correct results which are in line with the ones the Windows calculator produces down to their last decimal place (when the latter is set to radians of course).
The following will print the cosine of every angle between 0 and 2 pi:
Note that normally you'd format the output to make it look nicer...
The following will print the cosine of every angle between 0 and 2 pi:
Java Syntax (Toggle Plain Text)
double rad = 0.0; double interval = 0.1; while (rad < 2*Math.PI) { System.out.print(rad); System.out.print(" -> "); System.out.println(Math.cos(rad)); rad += interval; }
Note that normally you'd format the output to make it look nicer...
42
Yes, I got that answer too. But I thought 90 and 270 should yield a 0?
That is the thing I am talking about. Why would Cos90 and Cos270 in math.cos() be not 0?
So sorry, for the timebeing, my sourcecode is not with me. I can't post it here.
However my objective is to:
1)Calculate the cosine angle of x
WITHOUT using the math.cos()
2)It allows students or users to type in their desired
Angle in Degrees and Number of Terms to calculate.
More number of terms means more accurate calculation.
3)And error handling which I can handle.
CONCLUSION : The ultimate questions is,
1) Why math.cos() for 90 and 270 is not 0.
2) How do I not use math.cos() to calculate cosine.
I will be posting the cosine maths formula soon. Thank you!
Hope I am not confusing anyone! a BIG thank you for your overwhelming responses!
That is the thing I am talking about. Why would Cos90 and Cos270 in math.cos() be not 0?
So sorry, for the timebeing, my sourcecode is not with me. I can't post it here.
However my objective is to:
1)Calculate the cosine angle of x
WITHOUT using the math.cos()
2)It allows students or users to type in their desired
Angle in Degrees and Number of Terms to calculate.
More number of terms means more accurate calculation.
3)And error handling which I can handle.
CONCLUSION : The ultimate questions is,
1) Why math.cos() for 90 and 270 is not 0.
2) How do I not use math.cos() to calculate cosine.
I will be posting the cosine maths formula soon. Thank you!
Hope I am not confusing anyone! a BIG thank you for your overwhelming responses!
•
•
•
•
Originally Posted by dandan
System.out.println(Math.cos(Math.toRadians(90)));
System.out.println(Math.cos(Math.toRadians(270)));
gives
6.123233995736766E-17
-1.8369701987210297E-16
good enough for most purposes.
•
•
•
•
So sorry, for the timebeing, my sourcecode is not with me. I can't post it here.
However my objective is to:
1)Calculate the cosine angle of x
WITHOUT using the math.cos()
2)It allows students or users to type in their desired
Angle in Degrees and Number of Terms to calculate.
More number of terms means more accurate calculation.
http://www.maths.abdn.ac.uk/~igc/tch...pl/node59.html
And that's wat u meant by adding all the terms. Silly me?
*Voted best profile in the world*
yes.. with series...
Regarding to converting radians.. i had already converted right?
if("Calculate".equals(actionCommand))
d= Math.cos(Math.toRadians(d));
Regarding to converting radians.. i had already converted right?
if("Calculate".equals(actionCommand))
d= Math.cos(Math.toRadians(d));
•
•
•
•
Originally Posted by iamthwee
Oh i c wat u r trying to do now. Ur simply trying to evaluate the cos(x) using taylor's series?
http://www.maths.abdn.ac.uk/~igc/tch...pl/node59.html
And that's wat u meant by adding all the terms. Silly me?
This is the maths formula I am trying to get students to calculate using Java. Thank you.
http://img.photobucket.com/albums/v6...i/DSC00066.jpg
http://img.photobucket.com/albums/v6...i/DSC00066.jpg
![]() |
Other Threads in the Java Forum
- Previous Thread: help
- Next Thread: error when compiling
Views: 12358 | Replies: 27
| Thread Tools | Search this Thread |
Tag cloud for Java
add android applet application arguments array arraylist arrays binary c# c++ chat class classes client code component constructor convert data database db design desktop detection eclipse error event exception file forloop fractal givemetehcodez graphics gridlayout gui helpwithhomework homeworkassignment html ide image inheritance input integer interface j2me java javafx jframe jpanel jtextarea jtextfield key lazy linked linked-list list loop looping method methods mobile netbeans newbie node number object oracle output page parameter pattern pixel problem programming read recursion remove return robot scanner search server service set size sms sql string swing system text text-file threads timer transfer translate tree user web






