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

1 次查看(过去 30 天)
Between ei( vpa(5) ) and vpa( ei(5) ) which command would provide a higher precision for the integral ei(5) ?

采纳的回答

John D'Errico
John D'Errico 2020-11-16
编辑:John D'Errico 2020-11-16
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 个评论
Tuong Nguyen Minh
Tuong Nguyen Minh 2020-11-16
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

请先登录,再进行评论。

更多回答(0 个)

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by