How do ODE solvers compute error?

MATLAB documentation on odeset says that the solvers follow the rule e(i) ≤ max(RelTol*abs(y(i)),AbsTol(i)). My question is how does MATLAB compute e(i)? Since error is the difference between true and measured (or computed) value, how does MATLAB know the 'true' value of the solution at ith step?

Answers (1)

Jan
Jan on 5 Oct 2011
The true error between the calculated and the "real" trajectory cannot be computed. This is impossible even in theory, because the initial conditions cannot be determined 100% exactly.
The e(i) error is the difference between the two different discrtization schemes. E.g. ODE45 calculates one Runge-Kutta-scheme of order 4 and one of order 5. Then the difference between them can be used to estimate the local discretization error in the i-th step e(i).
The ODE solver tries to keep the e(i) a little bit smaller than the defined tolerances. If the step size is chosen much smaller, e(i) gets smaller also, but the larger number of steps let increase the global error due to the accumulation of rounding errors.
The explicite implementation of measuring the local discretization error and the definition of "a little bit" is magic, this means: there is no best method in general and no hard mathematical definition. E.g. is the elements of the vector y differs by several magnitudes, or one component of y differs by several magnitudes during the integration. Some integrators use the Wronski-matrix (the sensitivity to the initial conditions) to control the local discretization error. But even this methods needs the manual setting of some magic constants and a good choice of the scaling method.

5 Comments

can i take this error value e(i) out and use it in my calculation? i mean whether we can use this value or it is hidden and can not be passed to outside coding. thanks
It is not made available.
dbtype ode45
and look near line 277. You will see that err is not saved and is not passed to any of the output functions or event functions.
thanks for your reply! yet, if i want to do that, is there any way i can cope with this problem?
You could copy the file and edit it however you like. For example you could make the err available to the event functions, and then use the 5 output form of the modified ode45
thank you very much, i will try this!

Sign in to comment.

Asked:

on 5 Oct 2011

Commented:

on 24 Aug 2015

Community Treasure Hunt

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

Start Hunting!