Between ei(vpa(5)) and vpa (ei(5) ) which command would provide a higher precision for the integral ei(5) ?
2 次查看(过去 30 天)
显示 更早的评论
Between ei( vpa(5) ) and vpa( ei(5) ) which command would provide a higher precision for the integral ei(5) ?
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numbers and Precision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!