NaN for zero divide by zero.
이전 댓글 표시
Will illustrate with an example, I.e:
a = (0:0.1:1); b = (1-a)*2./(1-a);
Matlab will output the end value in b as NaN, when in reality b should converge to 2 for a = 1.
How can I avoid this?
채택된 답변
추가 답변 (3개)
Walter Roberson
2011년 4월 6일
1 개 추천
In order to avoid this, you will need to use the symbolic toolbox.
MATLAB is giving the correct numeric answer according to IEEE 754 floating point definitions. MATLAB works with actual values computed on real machines, not with limits or ideal values. See for example this portion of the FAQ
Sean de Wolski
2011년 4월 6일
0/0 is the definition of a nan
doc nan
Stian Molvik
2011년 4월 6일
0 개 추천
댓글 수: 1
Walter Roberson
2011년 4월 6일
Try this:
sym a
b = (1-a)*2/(1-a);
and see what b contains afterwards.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!