NaN for zero divide by zero.
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (3)
Walter Roberson
el 6 de Abr. de 2011
1 voto
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
el 6 de Abr. de 2011
0/0 is the definition of a nan
doc nan
Stian Molvik
el 6 de Abr. de 2011
0 votos
1 comentario
Walter Roberson
el 6 de Abr. de 2011
Try this:
sym a
b = (1-a)*2/(1-a);
and see what b contains afterwards.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!