User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,548 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,519 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 5764 | Replies: 27
Reply
Join Date: Jul 2005
Location: South East Asia , Singapore
Posts: 52
Reputation: LiBOC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
LiBOC's Avatar
LiBOC LiBOC is offline Offline
Junior Poster in Training

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

  #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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2006
Posts: 12
Reputation: dandan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
dandan dandan is offline Offline
Newbie Poster

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

  #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  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 191
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #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
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
in your main application frame should work wonders.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Jun 2004
Posts: 604
Reputation: freesoft_2000 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

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

  #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  
Join Date: Jul 2005
Location: South East Asia , Singapore
Posts: 52
Reputation: LiBOC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
LiBOC's Avatar
LiBOC LiBOC is offline Offline
Junior Poster in Training

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

  #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  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 191
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #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 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Jul 2005
Location: South East Asia , Singapore
Posts: 52
Reputation: LiBOC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
LiBOC's Avatar
LiBOC LiBOC is offline Offline
Junior Poster in Training

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

  #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  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

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

  #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  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

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

  #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

Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 191
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #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 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Other Threads in the Java Forum

All times are GMT -4. The time now is 9:00 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC