Producing incorrect results with abs command
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cole
el 4 de Sept. de 2022
Comentada: dpb
el 4 de Sept. de 2022
Hey, I am trying to do some pretty basic math here. The equation Im using is
which as a i understand would be written f8=abs(x.^x)-2.*x where x is a -10:10 matrix. However, when I run the code, the answers are incorrect. they should start at -20 but the code outputs 0E9. any ideas what I am missing?
2 comentarios
dpb
el 4 de Sept. de 2022
Dunno. Attach actual case that you think fails, don't just try to describe it to us...
Respuesta aceptada
Walter Roberson
el 4 de Sept. de 2022
You overlooked the "1.0e+09 *" part of the output. You are using format short, which displays only a limited number of decimal places for each item in order to create a compact display.
x = -10:10;
f8 = abs(x.^x) -2.*x;
f8
format long g
f8
4 comentarios
Más respuestas (1)
dpb
el 4 de Sept. de 2022
You didn't provide the input x array so we can (easily) duplicate, but now this one is easy... :)
You're confusing the output display with default format short compared to the actual result stored in memory.
NB: the "1.0e+09 *" at the beginning -- that's a common e-format multiplier applied on all results as printed. The result of the first location thus is reported as "0.000E9" which clearly doesn't have sufficient precision to show a value of 20-something on a 10E9 range.
Try looking at
f8(1)
all by itself and the mystery will go away.
0 comentarios
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
