I have used ode45 in Matlab. And, it is my understanding that the 4 and the 5 are for the order of the global and local error, respectively. So, the global error is on the order of $h^4$ and the local error is on the order of $h^5$, where $h$ is the step size.

But, then there's an option called RelTol, which you can set by: odeset('RelTol',1e-6).

How is it possible to set the relative tolerance lower than the global or local error in this case? Or is the name ode45 a bit of a misnomer?

  • 6
    $\begingroup$ It's not a misnomer, but a misunderstanding on your side -- as the documentation states: "ode45 is based on an explicit Runge-Kutta (4,5) formula, the Dormand-Prince pair". Furthermore, "order" in errors usually refers to the power of the stepsize (i.e., $\|y_h-y\| \leq C h^4$ would be "fourth order"), not a fixed error magnitude. The tolerance you specify is used to determine the step size $h$ to achieve the desired order. $\endgroup$ Dec 6, 2016 at 21:43
  • 3
    $\begingroup$ Keep in mind that the error control is local rather than global, so the error after n steps can be much larger than the error tolerance per step. $\endgroup$ Dec 6, 2016 at 22:46
  • $\begingroup$ @ChristianClason, so you're basically saying that the $||y_h - y||$ is the "RelTol" setting. And, to find the appropriate step size, you would solve this equation $||y_h - y|| \le Ch^4$ for $h$? $\endgroup$
    – Candic3
    Dec 6, 2016 at 23:55
  • $\begingroup$ No; that would be an absolute tolerance, a relative tolerance would be $\|y_h-y\|/\|y\|$. Also, you don't know $y$ (otherwise you wouldn't need to solve the ODE numerically), so you can't just solve for $h$. Rather, ode45 makes use of a sophisticated error estimator (that's where the 5 comes in) and reduces $h$ until the local error estimate satisfies (the sum of) both relative and global tolerance. $\endgroup$ Dec 7, 2016 at 7:38
  • $\begingroup$ Thanks. This guy seems to define the relative tolerance as dividing the absolute difference by the minimum of the estimate and the "true" value. But, you seem to think it's always the "true" value? mathworks.com/matlabcentral/answers/… $\endgroup$
    – Candic3
    Dec 7, 2016 at 17:48

1 Answer 1


And, it is my understanding that the 4 and the 5 are for the order of the global and local error, respectively.

Your understanding is wrong.

The local error of a Runge–Kutta method of order $n$ is proportional to $h^n$.

What ode45 does is to estimate the solution (of one step) with two Runge–Kutta methods with local orders of 4 and 5, respectively (hence those numbers). It uses the solution of the 5th-order method to estimate the solution of the ODE and the difference between the solutions from the two methods to estimate the error of the integration. Mind you that this is only an estimate – if you knew the precise error, you would also have already solved the problem precisely. To save computation time, the two Runge–Kutta methods are designed such that they use common intermediate results. Other embedded Runge–Kutta methods (i.e., Runge–Kutta methods with two numbers to indicate order) work similarly.

The error estimate is then used to optimise the step size: If the error is above a given tolerance (for each component), the step size is decreased until the error is below that tolerance. If the error is far below that tolerance, the step size in increased to save time. This tolerance is:

$$ \text{AbsTol}_i + \text{RelTol}·|\hat{y}_i|,$$

where $|\hat{y}_i|$ is the estimated solution.

  • 3
    $\begingroup$ You are correct; this is described in mathworks.com/help/pdf_doc/otherdocs/ode_suite.pdf. $\endgroup$ Dec 7, 2016 at 8:35
  • $\begingroup$ Thank you, @Wrzlprmft. I understand that the RK5 is used to find an estimate of the "true" value of $y$. But, if we use the RK5 to estimate the true value, then wouldn't it make sense to just use it to solve for the entire solution to the DE using RK5? Since, we have to compute it anyway for adaptive stepping. $\endgroup$
    – Candic3
    Dec 7, 2016 at 17:35
  • 1
    $\begingroup$ No, you use RK5 to estimate the error. That's a very different thing. (An estimate of the error is more useful here than a higher-order approximation since it allows you to take large time steps where small steps are not necessary, thus saving computational effort.) $\endgroup$ Dec 7, 2016 at 18:35
  • 1
    $\begingroup$ @Hunle: The estimate of the solution is obtained using the 5th-order method (see my edit). But with the solution from only one method, it’s impossible to obtain a robust estimate of the error. Therefore you need the second method. $\endgroup$
    – Wrzlprmft
    Dec 7, 2016 at 22:52
  • $\begingroup$ @ChristianClason no, the 5th order method is used for the stepping. This is known as local extrpolation. The 4th order embedded method is only used for error estimation. But the 4th order method is essentially free since it just is a different linear combination of the stages, so there's not much of an overhead for doing this. But ode45 is still "mostly" 4th order since it fills in extra values into the solution with a 4th order interpolation, even though its actual steps are 5th order. $\endgroup$ Oct 2, 2017 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.