The problem with using Java's maths.cos()

Reply

Join Date: Jul 2005
Posts: 73
Reputation: LiBOC is an unknown quantity at this point 
Solved Threads: 0
LiBOC's Avatar
LiBOC LiBOC is offline Offline
Junior Poster in Training

The problem with using Java's maths.cos()

 
0
  #1
Jan 24th, 2006
There are two things which I didn't or could not achieve with using maths.cos() from Java.

First - When I calculate cos90 or cos270, it gives me absurb values. It should be 0. Meaning it cannot calculate if the angle lies on X axis.

I tested with 91 or 271, gives a near 0 which is correct.

Second - I was figuring how do I include the number of terms to be calculated with my Cosine formula....

Lastly, I am using JFrames as my GUI and I can only properly exit from my menu bar. And not from the X button at top RH corner.

I would appreciate hints or guidance in solving the above 3 issues. Thank you so much people!
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 12
Reputation: dandan is an unknown quantity at this point 
Solved Threads: 1
dandan dandan is offline Offline
Newbie Poster

Re: The problem with using Java's maths.cos()

 
0
  #2
Jan 24th, 2006
Math.cos is using angles in radians. Try Math.cos(Math.toRadians(90)).

Second - I don't understand.

Try jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,186
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 220
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: The problem with using Java's maths.cos()

 
0
  #3
Jan 24th, 2006
If you properly set up the application you can exit the application normally (with JVM shutdown) by using the operating system supplied features (like the close icon in the window corner) as well.

Something like
  1. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
in your main application frame should work wonders.
42
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: The problem with using Java's maths.cos()

 
0
  #4
Jan 24th, 2006
Hi eveyone,

Originally Posted by LiBOC
Second - I was figuring how do I include the number of terms to be calculated with my Cosine formula
Use loops and arrays

Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond

Tell me what type of software do you like and what would you pay for it

http://www.daniweb.com/techtalkforums/thread19660.html
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 73
Reputation: LiBOC is an unknown quantity at this point 
Solved Threads: 0
LiBOC's Avatar
LiBOC LiBOC is offline Offline
Junior Poster in Training

Re: The problem with using Java's maths.cos()

 
0
  #5
Jan 24th, 2006
Yea, I had convert it into radians before putting it back into the default math.cos() method... but only 270 and 90 are wrong values!

Originally Posted by dandan
Math.cos is using angles in radians. Try Math.cos(Math.toRadians(90)).

Second - I don't understand.

Try jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,186
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 220
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: The problem with using Java's maths.cos()

 
0
  #6
Jan 25th, 2006
no, the rest is wrong as well (though it is possible that by some chance a few distinct values might happen to be identical it's unlikely).
But they're less obviously wrong unless you know what to expect. Do you know the exact cosine of every angle to 10 decimal places without looking them up?
42
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 73
Reputation: LiBOC is an unknown quantity at this point 
Solved Threads: 0
LiBOC's Avatar
LiBOC LiBOC is offline Offline
Junior Poster in Training

Re: The problem with using Java's maths.cos()

 
0
  #7
Jan 25th, 2006
Thanks.

I used the calculator program on my WinXP to counter check with my Java App. It is exactly correct. Only for 90 and 270 degrees. I also had converted them to radians.

And also, math.cos() method do not include terms if I am not wrong?

What if I want to write my own cosine formula that include a user-defined number of terms? Rewrite the formula into a java language? Solve the maths equation yourself?

can math.cos() do that?

Originally Posted by jwenting
no, the rest is wrong as well (though it is possible that by some chance a few distinct values might happen to be identical it's unlikely).
But they're less obviously wrong unless you know what to expect. Do you know the exact cosine of every angle to 10 decimal places without looking them up?
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: The problem with using Java's maths.cos()

 
0
  #8
Jan 25th, 2006
What are the values you are getting for 90 and 270? Shouldn't they both be 0 according to the unit circle?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,311
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 383
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: The problem with using Java's maths.cos()

 
0
  #9
Jan 25th, 2006
What if I want to write my own cosine formula that include a user-defined number of terms? Rewrite the formula into a java language? Solve the maths equation yourself?
What do u want to do? I still have no clue? What do u mean by number terms? You aren't making much sense. Please give us an example. R u trying to solve generic equasions like:

1/2cos x =75
1/2cos(3x) -5cos = 45
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,186
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 220
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: The problem with using Java's maths.cos()

 
0
  #10
Jan 25th, 2006
Originally Posted by server_crash
What are the values you are getting for 90 and 270? Shouldn't they both be 0 according to the unit circle?
yes, and when using radials they won't be 0 but roughly -.45 and +.98 respectively.
42
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 11709 | Replies: 27
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC