942,505 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 17703
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 24th, 2006
0

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

Expand Post »
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!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
LiBOC is offline Offline
73 posts
since Jul 2005
Jan 24th, 2006
0

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

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);
Reputation Points: 10
Solved Threads: 1
Newbie Poster
dandan is offline Offline
12 posts
since Jan 2006
Jan 24th, 2006
0

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

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
Java Syntax (Toggle Plain Text)
  1. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
in your main application frame should work wonders.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jan 24th, 2006
0

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

Hi eveyone,

Quote 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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jan 24th, 2006
0

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

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!

Quote 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);
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
LiBOC is offline Offline
73 posts
since Jul 2005
Jan 25th, 2006
0

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

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?
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jan 25th, 2006
0

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

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?

Quote 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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
LiBOC is offline Offline
73 posts
since Jul 2005
Jan 25th, 2006
0

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

What are the values you are getting for 90 and 270? Shouldn't they both be 0 according to the unit circle?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jan 25th, 2006
0

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

Quote ...
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:

Quote ...
1/2cos x =75
Quote ...
1/2cos(3x) -5cos = 45
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jan 25th, 2006
0

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

Quote 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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: help
Next Thread in Java Forum Timeline: error when compiling





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC