Why do I receive an inaccurate value of e (Euler's Number) when I do exp(1) in MATLAB?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 27 de Jun. de 2009
Editada: MathWorks Support Team
el 6 de Feb. de 2014
If I execute the following code to get e, Euler's Number to 100 decimal places,
digits(100)
one = vpa(1)
b = vpa(exp(one))
I get:
b =
2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427
However, if I execute:
a = exp(1)
I get:
a = 2.718281828459046
Note that this number is not a rounded or truncated version of Euler's constant e, and is not the best double precision value for e.
Respuesta aceptada
MathWorks Support Team
el 18 de Oct. de 2013
This is due to double precision roundoff error introduced due by the double 1 in exp(1). Note that if I execute the following,
eps(exp(1))
I get,
ans =
4.440892098500626e-016
which is enough error at the value exp(1) to allow for the difference in the theoretical and double precision values. Thus, the value provided by exp(1) is within eps of the theoretical value.
0 comentarios
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!