Between ei(vpa(5)) and vpa (ei(5) ) which command would provide a higher precision for the integral ei(5) ?

2 visualizaciones (últimos 30 días)
Between ei( vpa(5) ) and vpa( ei(5) ) which command would provide a higher precision for the integral ei(5) ?

Respuesta aceptada

John D'Errico
John D'Errico el 16 de Nov. de 2020
Editada: John D'Errico el 16 de Nov. de 2020
Is this a homework assignment? My spidey sense is tingling. However, a quick glance at your other questions suggests you are hopefully past that point. But then you should understand how to know the answer. In any case, think about how MATLAB works. What does the first case do?
ei(vpa(5))
ans =
40.185275355803177455091421793796
This converts the number 5, to a high precision symbolic representatino of the number 5. Then it calls the symbolic version of ei.
Instead, what does the latter case do? It first computes
ei(5)
ans =
40.1852753558032
It uses the DOUBLE PRECISION version of ei. And then passes that result directly to vpa.
vpa(ei(5))
ans =
40.185275355803177887992205796763
And while they look the same to 16 digits or so, after that point, the second case is the one that is in error. The first one used the symbolic version of ei to compute the result to high precision.
Remember that in the second case MATLAB does not know that eventually, it will want a symbolic result. So you get a result that is accurate in DOUBLE PRECISION. And THEN it passes the result to vpa. This is how all function calls in MATLAB work. They don't look beyond that point to know what will be done with the result. MATLAB computes the result from the inside call, and only then does it worry about the next step.
  1 comentario
Tuong Nguyen Minh
Tuong Nguyen Minh el 16 de Nov. de 2020
Haha thank you, this is not a homework assignments. Actually, I do not understand the way symbolic calculation work so I really appreciate your careful and detail answer

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by