How accurate is the numerical integrator, cumtrapz?

3 vues (au cours des 30 derniers jours)
Noob
Noob le 11 Juin 2017
Modifié(e) : Noob le 19 Juin 2017
How accurate is the numerical integrator, cumtrapz?

Réponse acceptée

Walter Roberson
Walter Roberson le 11 Juin 2017
Modifié(e) : Walter Roberson le 11 Juin 2017
There is no bound to the error of cumtrapz()
Consider f = x^3-sin(x) over 0 to 5, with step size 1/1000, then the numeric error from the trapazoid rule is about 6E-6.
Now consider f = 1000*cot(Pi*x-2) over 0 to 1/2, with step size 1/1000, then the numeric error from the trapazoid rule is about 1E-4 . This is 1/10th of the range that produced the 6E-6 error for the first function, so if it were range alone that made the difference than you would expect around 6E-7 error. If you were to then examine and say "Oh but the multiplier is 1000 times more" then that would at get you to about 6E-4 error, more than the 1E-4 observed. We can thus determined that there must be more factors than just constant multipliers or length of the range: the numeric error must depend upon the shape of the function itself.
Now consider f = cot(Pi*x-2) over 0 to 5, with step size 1/1000, then the numeric error from the trapazoid rule is undefined, as the calculation would involve adding values that range from -inf to +inf and adding -inf to +inf is undefined. So it definitely depends upon the function being evaluated.
You can calculate the error symbolically. The trapazoid rule estimate of the integral of F from A to B step size H is
(symsum(F(k*H), k, 1, B/H-1)+(1/2)*F(A)+(1/2)*F(B))*H
from which you can subtract int(F,A,B) to get the error.
  1 commentaire
Stephen23
Stephen23 le 11 Juin 2017
Modifié(e) : Stephen23 le 11 Juin 2017
+1 maths wins again :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations 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!

Translated by