what is mean by NaN and inf in matlab?

14 views (last 30 days)
when I computing an equation in Matlab I got a matrix. and some of its values are NaN and Inf. can I move on this matrix or is this an error?
  1 Comment
Adam
Adam on 21 Feb 2017
You could always try
doc inf
doc nan
for questions like this.
Matlab has some of the best (the best of what I have used) documentation of any similar software. I have been working in Matlab for 10 years now and there is never a day when I don't open multiple tabs of the documentation to remind myself something, learn something new, look for a solution to something, etc, etc.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Feb 2017
inf is positive infinity. That is given when calculations overflow the largest representable floating point number (which is about 10^308).
-inf is negative infinity. It is given when calculations overflow the negative of the largest representable floating point number (so, about -10^308)
NaN is "Not A Number". It is given when the calculation gives a result that is undefined. The two main calculations that can lead to NaN are (0/0) and (inf - inf), which includes (+inf)+(-inf)
If you have a matrix containing inf and you do algebraic matrix multiplication by a matrix that includes both negative and positive numbers, then the (+inf)+(-inf) case becomes likely to occur, giving you a NaN output.
If you have a / or ./ operator in your code, you probably have division by 0.
If you have a det() in your numeric code for anything other than "For Amusement Purposes Only", then you probably have a division by 0 or you are probably creating an infinity.
If you have inv() in your code then you are probably creating an infinity due to overflow, and that often turns into NaN.
Can you move on? Possibly. You probably need to choose a different algorithm. You might need to use the \ algorithm.
  4 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!