Results 1 to 5 of 5
- 10-11-2012, 12:29 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 31
- Rep Power
- 0
How to make a number not infinite
Alright so in my math class my teacher wants us to buy a 100 dollar Calculator inwich i cant offored. So I am now designing a calculator that will do everything I need the other one to do. Currently i am trying to find the correlation Coeffiecent everything works fine so fare except in the formula there is a line
So after some trouble shooting i have found for a fact that my problem is the Math.sqrt.It returns a infinite number so I get nan instead of the Answer. Would any of you happen to know how to make my answer go from infinite to terminating.Please help right away i need to do my homework.Java Code:r = Math.sqrt(totalPoints*xTotalSquared-Math.pow(xTotal,2);
- 10-11-2012, 04:00 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: How to make a number not infinite
Generally NaN is considered a "feature".
Some mathematical expressions are syntactically correct, but make no sense in practice. For example you can use trigonometry to find the angles of a triangle given the sides. It's a nice expression, and all goes well until you substitute in the values 1 - 1 - 100 as the sides of the triangle: there simply is no such triangle or angles to be found in this case. The computing result in such cases is often NaN.
The best attitude, on encountering a NaN result, is not to wonder how to avoid it, but, rather, ask "why does this occur?", "am I calculating the right thing?", "am I calculating the right thing, but in an invalid context?".
---
According to the API docs Math.sqrt() will return NaN if you try to evaluate the square root of a negative number.
n*sigma(x^2) - sigma(x)^2 looks ok for the variance in one direction. Ie it's not obvious why the thing in the sqrt() should be negative if "total" means what it ought to mean. But, almost certainly, you are trying to find the square root of a negative quantity and the reason for that lies elsewhere in your code. Consider posting a SSCCE that shows the NaN occurring.
- 10-11-2012, 04:08 AM #3
Member
- Join Date
- Oct 2012
- Posts
- 31
- Rep Power
- 0
Re: How to make a number not infinite
Thanks you just help me solve it. It was because of the whole negative thing and i already know how to fix it thank you so much
- 10-11-2012, 04:35 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: How to make a number not infinite
You're welcome.
- 10-11-2012, 09:27 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: How to make a number not infinite
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
how to make grid number ?
By nikiiz in forum New To JavaReplies: 6Last Post: 05-28-2012, 05:02 PM -
infinite loop
By javapink in forum New To JavaReplies: 19Last Post: 03-06-2011, 02:28 AM -
how to end infinite loop
By search4survival in forum New To JavaReplies: 14Last Post: 10-25-2010, 08:59 AM -
how do i make a string return a number?
By pjr5043 in forum New To JavaReplies: 6Last Post: 09-15-2008, 04:56 AM -
Will make a pyramid of some kind out of a number
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:20 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks