Between ei(vpa(5)) and vpa (ei(5) ) which command would provide a higher precision for the integral ei(5) ?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tuong Nguyen Minh
le 16 Nov 2020
Commenté : Tuong Nguyen Minh
le 16 Nov 2020
Between ei( vpa(5) ) and vpa( ei(5) ) which command would provide a higher precision for the integral ei(5) ?
0 commentaires
Réponse acceptée
John D'Errico
le 16 Nov 2020
Modifié(e) : John D'Errico
le 16 Nov 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numbers and Precision dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!