Difference between NAN & INF in MATLAB?

Viewed 278

In MATLAB, INF means infinity and NAN means Not a Number

Apparently both these seem similar but there must be some difference ,because of which MATLAB makes represents them separatley? Why in some operations output is Inf while in others , output is NAN?

1 Answers

Mathematically they are two different concepts. While in real analysis, infinity is not a real number it does represent an unbounded limit and is part of the set that makes up extended real numbers. That makes infinity a symbol that can result from a mathematical operation, i.e. it is a valid answer.

A NaN, on the other hand, represents a result that is not numerical.

I like to initialize floating point arrays when allocated to NaN because it will make certain bugs (e.g. off by one errors) obvious.

Related