2  Numerical Methods for IVPs

Author
Affiliation

Enrico Bertolazzi

University of Trento, Department of Industrial Engineering

In many cases, finding an analytical solution to initial value problems (IVPs) is either impossible or impractical due to the complexity of the integrals involved. Therefore, numerical methods are commonly used to approximate solutions. These methods can be applied not only to single IVPs but also extend naturally to systems of differential equations. Additionally, since higher-order differential equations can be reformulated as systems of first-order equations, we will focus on numerical methods for first-order systems.

Definition 2.1 (Time Discretization) On a time interval I=[t_0,t_0+T], introduce a mesh

t_0<t_1<\cdots<t_N=t_0+T.

The k-th time step is the subinterval

I_k=[t_k,t_{k+1}], \qquad k=0,1,\ldots,N-1,

with step size

h_k=t_{k+1}-t_k>0.

For a uniform mesh, h_k=h=T/N for every k. Using N for the number of time steps avoids confusing it with the dimension of the ODE system.

Numerical methods for solving IVPs are divided into two primary categories: one-step methods and multi-step methods. In one-step methods, the next approximation z_{k+1} depends only on the current step z_k. In contrast, multi-step methods calculate z_{k+1} using information from several previous time levels. The number of previous levels (the number of steps) must not be confused with the order of accuracy of the method.

Definition 2.2 (One-Step Methods)  

Explicit Methods

An explicit method (also called forward integration) calculates approximations sequentially. Starting with an initial condition z_0 at time t_0, it computes the sequence z_1, z_2, \dots, z_n using the following update formula:

\bm{z}_{k+1} = \bm{z}_{k} + \Delta t_k \bm{F}(t_k, \bm{z}_{k}, \dots, \bm{z}_{k-p}; \Delta t_k)

Here, \bm{F} is called the increment function, which determines the change from one time step to the next. Here p+1 indicates how many previously computed states enter the increment function; it is not the order of accuracy. A one-step method depends only on \bm{z}_k.

Definition 2.3 (Implicit Methods) An implicit method (also called backward integration) is similar in structure to explicit methods but requires solving for the new value z_{k+1} implicitly. The update formula is given by:

\bm{z}_{k+1} = \bm{z}_k + \Delta t_k \bm{F}(t_{k+1}, \bm{z}_{k+1}, \bm{z}_{k},\dots, \bm{z}_{k-p};\Delta t_k)

In this case, the increment function \bm{F} depends on \bm{z}_{k+1}, meaning the equation must be solved iteratively or using numerical techniques to find \bm{z}_{k+1}. Implicit methods often provide better stability, especially for stiff differential equations, but are computationally more intensive because of the need to solve for \bm{z}_{k+1} at each step.

In summary, the distinction between explicit and implicit methods is primarily in how the next step is computed. Explicit methods are generally simpler but may require smaller time steps for stability, whereas implicit methods can handle larger time steps but at the cost of increased computational effort.

2.1 A First Look at the Explicit Euler Method

Before introducing the general convergence theory for one-step methods, it is useful to see the complete argument in the simplest possible setting. We therefore consider first the scalar initial value problem

\left\{ \begin{aligned} y'(t) &= f(y(t),t),\\ y(a) &= y_a, \end{aligned} \right.

on the interval [a,b]. Let

t_k=a+kh, \qquad h=\frac{b-a}{N}, \qquad k=0,1,\ldots,N.

Derivation from Taylor’s Formula

Assume for the moment that the exact solution y(t) is sufficiently smooth. Taylor’s formula gives

y(t+h) = y(t)+h y'(t)+\mathcal O(h^2).

Since the differential equation gives

y'(t)=f(y(t),t),

we obtain

y(t+h) = y(t)+h f(y(t),t)+\mathcal O(h^2).

If h is small, the quadratic remainder can be neglected and we obtain the approximation

y(t+h)\approx y(t)+h f(y(t),t).

Applying the same idea successively at the mesh points leads to the explicit Euler method

\boxed{ \begin{aligned} y_0 &= y_a,\\ y_{k+1} &= y_k+h f(y_k,t_k), \qquad k=0,1,\ldots,N-1. \end{aligned} }

Geometrically, at every point (t_k,y_k) the method follows for one time step the tangent line whose slope is f(y_k,t_k). The new point is then used to compute the tangent for the following step.

A Direct Error Estimate for Euler

The preceding derivation suggests that the error made in one step is of order h^2. We now show directly how these one-step errors accumulate.

Let

e_k=y(t_k)-y_k

be the global error. Taylor’s theorem with Lagrange remainder gives

y(t_{k+1}) = y(t_k) +h f(y(t_k),t_k) +\frac{h^2}{2}y''(\xi_k), \qquad \xi_k\in(t_k,t_{k+1}).

Euler’s method gives

y_{k+1}=y_k+h f(y_k,t_k).

Subtracting the two relations yields

e_{k+1} = e_k +h\left[f(y(t_k),t_k)-f(y_k,t_k)\right] +\frac{h^2}{2}y''(\xi_k).

Assume that f is Lipschitz continuous with respect to y,

|f(y,t)-f(z,t)|\le L|y-z|,

and define

M_2=\max_{t\in[a,b]}|y''(t)|.

Then

|e_{k+1}| \le (1+hL)|e_k|+\frac{h^2}{2}M_2.

It is convenient to write

A=1+hL, \qquad B=\frac{h^2}{2}M_2.

Since the initial condition is imposed exactly, e_0=0. Hence

\begin{aligned} |e_1| &\le B,\\ |e_2| &\le AB+B=(1+A)B,\\ |e_3| &\le A(1+A)B+B=(1+A+A^2)B, \end{aligned}

and, in general,

|e_k| \le \left(1+A+\cdots+A^{k-1}\right)B.

Using the geometric-series formula,

|e_k| \le \frac{A^k-1}{A-1}B = \frac{(1+hL)^k-1}{hL}\,\frac{h^2}{2}M_2.

Since

1+x\le e^x,

we have

(1+hL)^k\le e^{khL}=e^{(t_k-a)L}\le e^{(b-a)L}.

Therefore, for L>0,

\boxed{ |e_k| \le \frac{e^{(b-a)L}-1}{2L}\,M_2\,h }

for every k=0,1,\ldots,N. Consequently,

\boxed{ \max_{0\le k\le N}|y(t_k)-y_k|\le Ch, }

where C is independent of h. Thus the explicit Euler method converges with global order one.

This elementary calculation already contains the essential mechanism:

\boxed{ \text{one-step defect }\mathcal O(h^2) \quad\Longrightarrow\quad \text{global error }\mathcal O(h). }

The next theorem abstracts exactly this argument and applies it to a general one-step method.

Consistency, Local Error, and Convergence

A large class of one-step methods can be written as

\bm{z}_{k+1}=\bm{z}_k+h\,\bm\Phi(t_k,\bm{z}_k;h),

where \bm\Phi is the increment function. To discuss accuracy, it is useful to distinguish the error made in one exact step from the error accumulated over many steps.

Definition 2.4 (Local Defect and Order) Let \bm{z}(t) be the exact solution. The local defect is

\bm{d}_{k+1} = \bm{z}(t_{k+1})-\bm{z}(t_k) -h\,\bm\Phi(t_k,\bm{z}(t_k);h).

The method has local order p+1, or equivalently global order p under the stability hypotheses below, if

\|\bm{d}_{k+1}\|\le C h^{p+1}

uniformly on every fixed finite time interval. It is consistent if

\frac{\|\bm{d}_{k+1}\|}{h}\longrightarrow0 \qquad (h\to0).

The global error is

\bm{e}_k=\bm{z}(t_k)-\bm{z}_k.

The distinction is essential: a local defect O(h^{p+1}) is produced at each of approximately T/h steps, so one expects a global error O(h^p) provided perturbations are not amplified too strongly.

Theorem 2.1 (Convergence Theorem for One-Step Methods) Assume that, for 0<h\le h_0, the increment function is uniformly Lipschitz in the state variable,

\|\bm\Phi(t,\bm{x};h)-\bm\Phi(t,\bm{y};h)\| \le L_\Phi\|\bm{x}-\bm{y}\|,

and that the local defect satisfies

\|\bm{d}_{k+1}\|\le C h^{p+1}.

Then, on a fixed interval [t_0,t_0+T], the global error satisfies

\boxed{ \|\bm{e}_k\| \le \frac{C}{L_\Phi} \left(e^{L_\Phi(t_k-t_0)}-1\right)h^p }

when L_\Phi>0, with the limiting bound CT h^p when L_\Phi=0. In particular, the method converges with order p.

Proof

Subtracting the numerical step from the exact step gives

\bm{e}_{k+1} = \bm{e}_k +h\left[ \bm\Phi(t_k,\bm{z}(t_k);h) - \bm\Phi(t_k,\bm{z}_k;h) \right] + \bm{d}_{k+1}.

Hence

\|\bm{e}_{k+1}\| \le (1+hL_\Phi)\|\bm{e}_k\|+Ch^{p+1}.

Since \bm{e}_0=0, iteration yields

\|\bm{e}_k\| \le Ch^{p+1} \sum_{j=0}^{k-1}(1+hL_\Phi)^j.

For L_\Phi>0,

\begin{aligned} \|\bm{e}_k\| &\le \frac{C}{L_\Phi} \left[(1+hL_\Phi)^k-1\right]h^p \\ &\le \frac{C}{L_\Phi} \left(e^{L_\Phi(t_k-t_0)}-1\right)h^p. \end{aligned}

This proves the result. \square

This theorem is the basic finite-time mechanism behind the rule

\text{local error }O(h^{p+1}) \quad\Longrightarrow\quad \text{global error }O(h^p).

Note the structure of the bound: the local defects accumulate, and the accumulation is amplified by the factor e^{L_\Phi(t_k-t_0)}. This is exactly the amplification of the continuous-dependence estimate obtained from Grönwall’s lemma — same structure, same reason. The constant degrades exponentially with the length of the integration interval, which is why a global error bound of this type is informative on a fixed interval and essentially useless for long-time integration.

TipWhere L_\Phi comes from

For explicit Euler \bm\Phi=\bm{f}, so L_\Phi=L, the Lipschitz constant of \bm{f}. For a multistage method \bm\Phi is a composition of evaluations of \bm{f} and one obtains L_\Phi=L\bigl(1+\mathcal O(hL)\bigr). The Lipschitz property of \bm{f} is therefore the only substantial hypothesis — the same one that guarantees existence and uniqueness of the solution, Picard–Lindelöf theorem. Without it there is neither a unique solution to approximate nor a convergence statement to prove.

WarningWhat the theorem does not say

The estimate holds as h\to0 on a fixed interval. It says nothing about the behaviour as k\to\infty at fixed h: that is the subject of absolute stability, a property entirely independent of the order p. A method of order four can produce a numerical solution that grows without bound on a stiff problem, and the convergence theorem is not violated — it simply does not apply to that regime.

2.2 Euler Method in Vector Form

The Euler method is the simplest one-step numerical method for solving initial value problems (IVPs). One intuitive way to derive this method is through the truncated Taylor series expansion.

Consider the following IVP:

\left\{ \begin{aligned} \bm{z}'(t) &= \bm{f}(\bm{z},t), \\[0.25em] \bm{z}(t_0) &= \bm{z}_0, \end{aligned} \right.

The Taylor series expansion of the solution \bm{z}(t) around t_0 gives us:

\bm{z}(t_0 + \Delta t) = \bm{z}(t_0) + \Delta t\,\bm{z}'(t_0)+ \mathcal{O}(\Delta t^2),

where \bm{z}'(t_0) = \bm{f}(\bm{z}_0,t_0). Neglecting higher-order terms, we approximate \bm{z}(t_0 + \Delta t) as:

\bm{z}(t_0 + \Delta t) \approx \bm{z}(t_0) + \Delta t \bm{z}'(t_0),

The difference between this approximation and the exact solution \bm{z}(t_0 + \Delta t) is proportional to \Delta t^2, meaning the error decreases as \Delta t becomes smaller.

General Form of the Euler Method

To generalize this for any time interval I = [t_0, t_0 + T], we divide the interval into subintervals and apply the approximation at each step. For the k-th subinterval

I_k = [t_{k-1}, t_k]

the explicit Euler method for the k-th step is given by:

\bm{z}_{k+1} = \bm{z}_k + \Delta t\bm{f}(\bm{z}_k,t_k), \quad k = 0,1,\dots,n-1,

where \Delta t is the step size.

On the other hand, the implicit Euler method is

\boxed{\bm{z}_{k+1}=\bm{z}_k+\Delta t\,\bm{f}(\bm{z}_{k+1},t_{k+1})}, \qquad k=0,1,\ldots,n-1.

The right-hand side depends on the unknown \bm{z}_{k+1}, so a nonlinear algebraic system generally has to be solved at every step.

Solving the implicit Euler step

Define the nonlinear residual

\bm{G}(\bm{w}) = \bm{w}-\bm{z}_k-h\bm{f}(\bm{w},t_{k+1}).

The new state is the root \bm{G}(\bm{z}_{k+1})=\bm0. If \bm{f} is differentiable with respect to the state, Newton’s method gives

\boxed{ \bm{w}^{(m+1)} = \bm{w}^{(m)} - \left[\bm{I}-h\bm{J}_{\bm{f}}(\bm{w}^{(m)},t_{k+1})\right]^{-1} \bm{G}(\bm{w}^{(m)}) }.

In implementation one solves the linear system

\left[\bm{I}-h\bm{J}_{\bm{f}}(\bm{w}^{(m)},t_{k+1})\right]\bm{s}^{(m)} =-\bm{G}(\bm{w}^{(m)})

and sets \bm{w}^{(m+1)}=\bm{w}^{(m)}+\bm{s}^{(m)}; the inverse is not formed explicitly. A natural initial guess is the explicit Euler predictor

\bm{w}^{(0)}=\bm{z}_k+h\bm{f}(\bm{z}_k,t_k).

The nonlinear iteration should be stopped when both the residual and/or the Newton correction are sufficiently small relative to the requested ODE accuracy. Solving the nonlinear system much more accurately than the time-discretization error is usually unnecessary.

Convergence and Stability

Both the explicit and implicit Euler methods are first-order accurate, meaning that their local truncation error is \mathcal{O}(\Delta t^2), leading to a global error that scales as \mathcal{O}(\Delta t). As the step size \Delta t\to 0, both methods converge to the exact solution, with the error at any time

t \in I = [t_0, t_0 + T],

bounded by C \Delta t, where C is a constant. However, in practice, this constant can grow exponentially with T, following

C \propto e^{L T},

where L is the Lipschitz constant of the function \bm{f}(\bm{z},t). This growth in error amplification is particularly problematic for large-time integration.

Local and global error

For a one-step method, the local truncation error is the defect produced by one step when the exact value is supplied at the beginning of the step. The global error is

\bm{e}_k=\bm{z}(t_k)-\bm{z}_k.

For explicit Euler, if \bm{z}\in C^2 and \bm{f} is Lipschitz in \bm{z} with constant L, Taylor’s theorem gives a local defect bounded by C_0h^2. The error recursion satisfies

\|\bm{e}_{k+1}\|\le(1+hL)\|\bm{e}_k\|+C_0h^2.

Iterating this inequality and using (1+hL)^k\le e^{L(t_k-t_0)} yields

\boxed{\|\bm{e}_k\|\le \frac{C_0}{L}\bigl(e^{L(t_k-t_0)}-1\bigr)h}

for L>0 (with the obvious limit C_0(t_k-t_0)h when L=0). This proves first-order convergence on every fixed finite interval.

Stability Considerations

One of the key differences between the explicit and implicit Euler methods lies in their stability properties. The explicit Euler method has a stability constraint dictated by the step size \Delta t, requiring \Delta t to be sufficiently small to ensure numerical stability. Specifically, for a linear test equation of the form

\frac{\mathrm{d}z}{\mathrm{d}t} = \lambda z, \quad \lambda \in \mathbb{C}

the explicit Euler method is stable only if h satisfies the stability condition:

|1 + \Delta t\lambda| \leq 1.

For stiff problems, where solutions evolve on vastly different time scales and exhibit rapid transient dynamics, this condition can impose severely restrictive time-step limitations, making explicit Euler impractical.

In contrast, the implicit Euler method has stability function R(q)=1/(1-q), q=\Delta t\,\lambda. Its absolute-stability region contains the entire left half-plane: it is therefore A-stable. Moreover R(q)\to0 as |q|\to\infty in the left half-plane, so implicit Euler is also L-stable. “Unconditionally stable” should only be understood in this precise test-equation sense, not as a statement that every numerical problem is stable for arbitrary step sizes. This property makes it particularly advantageous for stiff problems, where it allows for significantly larger time steps without numerical instability. However, this comes at the cost of solving a nonlinear equation at each step, increasing computational expense.

Thus, while both methods share the same convergence rate of \mathcal{O}(\Delta t), their stability properties determine their applicability:

  • Explicit Euler: Suitable for non-stiff problems but requires small \Delta t for stability.
  • Implicit Euler: More robust for stiff problems, allowing larger \Delta t, but requires solving implicit equations at each step.

What is stiffness?

There is no single definition of stiffness that covers every nonlinear problem, but the computational phenomenon is clear: a problem is called stiff when stability, rather than accuracy, forces an explicit method to use a step size much smaller than the time scale on which the solution of interest changes.

For the linear system

\bm{z}'=\bm{A}\bm{z},

suppose the eigenvalues of \bm{A} have negative real parts. Each eigenmode behaves approximately like e^{\lambda_i t}. If some modes decay extremely rapidly while others decay slowly, an explicit method must resolve the fastest stable mode even after that transient has become negligible.

When all relevant eigenvalues are real and negative, the heuristic stiffness ratio

\kappa_{\rm stiff} = \frac{\max_i |\lambda_i|}{\min_i |\lambda_i|}

measures the separation of decay time scales. A large value is an indication of stiffness, not a universal definition. For general non-normal or nonlinear systems, eigenvalues alone may not capture the whole phenomenon.

This explains why A-stable and especially L-stable implicit methods are useful: they can strongly damp rapidly decaying modes without forcing h to resolve their shortest time scale.

2.3 Stability: continuous problem versus numerical method

The word stability is used for several distinct concepts. Keeping them separate prevents a common source of confusion.

Stability of the continuous IVP

For two exact solutions of

\bm{z}'=\bm{f}(\bm{z},t),

with nearby initial data, continuous dependence gives, under a Lipschitz assumption,

\|\bm{z}(t)-\widetilde{\bm{z}}(t)\| \le e^{L|t-t_0|} \|\bm{z}_0-\widetilde{\bm{z}}_0\|.

This is a property of the differential equation, not of a discretization.

Zero-stability and propagation of perturbations

A numerical method is also affected by perturbations: roundoff, inexact nonlinear solves, perturbed starting values, and local truncation errors. For one-step methods, a Lipschitz bound on the increment function provides the required finite-time stability. For linear multistep methods the corresponding concept is zero-stability, treated in the dedicated chapter.

Absolute stability

Absolute stability addresses a different question: whether a numerical method reproduces the decay of the scalar test problem

z'=\lambda z, \qquad \operatorname{Re}\lambda<0.

If a method gives

z_{n+1}=R(q)z_n, \qquad q=h\lambda,

its absolute-stability region is

\mathcal S=\{q\in\mathbb C:|R(q)|\le1\}.

This is a property of the numerical method applied to the test equation; it is not the same as convergence or stability of the exact IVP.

A-stability and L-stability

A method is A-stable if

\{q\in\mathbb C:\operatorname{Re}q\le0\}\subseteq\mathcal S.

Thus every exponentially decaying scalar mode is numerically stable for every step size. A method is L-stable if it is A-stable and additionally

R(q)\to0 \qquad\text{as }|q|\to\infty, \quad \operatorname{Re}q<0.

L-stability is especially useful for stiff problems because very fast stable modes are strongly damped rather than merely kept bounded.

These notions form a hierarchy of different questions:

  1. well-posedness / continuous dependence concerns the exact ODE;
  2. consistency measures the one-step defect of the discretization;
  3. zero-stability or one-step stability controls perturbation growth;
  4. convergence asks whether the numerical solution approaches the exact one as h\to0;
  5. absolute, A-, and L-stability describe behavior for decaying test modes at finite step size.

2.4 Heun and Collatz Methods

Heun’s Method

Heun’s method, also known as the improved Euler method, is a second-order numerical method for solving initial value problems (IVPs). It refines the accuracy of the explicit Euler method by incorporating an additional correction step.

Consider the IVP:

\left\{ \begin{aligned} \bm{z}'(t) &= \bm{f}(\bm{z},t), \\[0.25em] \bm{z}(t_0) &= \bm{z}_0, \end{aligned} \right.

Similar to the Euler method, Heun’s method begins by estimating the next step using the explicit Euler approximation:

\tilde{\bm{z}}_{k+1} = \bm{z}_k + \Delta t\bm{f}(\bm{z}_k,t_k).

This intermediate value \tilde{\bm{z}}_{k+1} is then used to refine the estimate by averaging the slopes at t_k and t_{k+1}:

\bm{z}_{k+1} = \bm{z}_k + \frac{\Delta t}{2} \left[ \bm{f}(\bm{z}_k,t_k) + \bm{f}(\tilde{\bm{z}}_{k+1},t_{k+1}) \right].

This two-stage approach makes Heun’s method more accurate than explicit Euler, achieving a global error of \mathcal{O}(\Delta t^2) instead of \mathcal{O}(\Delta t).

Convergence and Stability

Heun’s method is second-order accurate, meaning that its local truncation error is \mathcal{O}(\Delta t^3), leading to a global error of \mathcal{O}(\Delta t^2). Compared to the explicit Euler method, it provides improved accuracy for the same step size.

In terms of absolute stability, Heun’s method is conditionally stable. For the scalar test equation its stability polynomial is

R(q)=1+q+\frac{q^2}{2}.

Along the negative real axis the stability interval is again [-2,0], exactly as for explicit Euler; therefore second-order accuracy does not automatically imply a less restrictive step-size bound on purely dissipative scalar problems. The two-dimensional stability regions are different, but neither statement should be reduced to the vague claim that one is simply “more stable.” Like every explicit Runge–Kutta method, Heun’s method remains unsuitable for strongly stiff problems when stability forces very small steps.

Collatz Method

The Collatz method, is another improvement over the Euler method. It introduces multiple stages to achieve better accuracy by approximating the solution using additional intermediate steps.

Formulation of the Collatz Method

For a given step size \Delta t, the Collatz method approximates the solution as follows:

  1. Compute an initial (half) Euler step: \tilde{\bm{z}} = \bm{z}_k + \frac{\Delta t}{2} \bm{f}\left(t_k, \bm{z}_k\right).

  2. Compute a midpoint correction: \bm{z}_{k+1} = \bm{z}_k + \Delta t\bm{f}\left(t_k + \frac{\Delta t}{2}, \tilde{\bm{z}} \right).

This results in overall second-order accuracy. The improvement over explicit Euler is primarily one of accuracy; its absolute-stability properties must be analyzed separately.

Convergence and Stability

Like Heun’s method, the Collatz method achieves a global error of \mathcal{O}(\Delta t^2), making it more accurate than the first-order Euler method. For the scalar test equation, its stability polynomial is R(q)=1+q+q^2/2, the same as Heun’s method. Thus the two methods have the same absolute-stability region; neither has a larger stability region than the other.

However, similar to Heun’s method, the Collatz method is still not unconditionally stable and may require small step sizes for stiff problems.

Comparison of Methods

Method Order of Accuracy Stability Advantages Disadvantages
Explicit Euler \mathcal{O}(\Delta t) Conditionally stable Simple and fast Requires small \Delta t for stability
Heun’s Method \mathcal{O}(\Delta t^2) Improved but not unconditionally stable More accurate than Euler Still requires small h for stiff problems
Collatz (midpoint) \mathcal{O}(\Delta t^2) Same test-equation stability polynomial as Heun Two-stage, second order Still unsuitable for strongly stiff problems

Both Heun’s and Collatz methods improve upon the Euler method by incorporating corrections that enhance accuracy and stability, making them more suitable for practical numerical integration.

2.5 Numerical Verification of the Order

Whenever a method is implemented — or an existing implementation is used on a new problem — the observed order should be checked against the theoretical one. The test is cheap, it catches most coding mistakes, and it is the only practical way to confirm that the convergence theory applies to the problem at hand.

The Estimator

A method has order p when the maximum error over the mesh,

E_h=\max_{0\le k\le N}\bigl|y_k-y(t_k)\bigr|,

behaves like

E_h\approx C h^{p}, \tag{2.1}

with C depending on the problem but not on h. Computing the solution with two step sizes h_1 and h_2 and taking the ratio,

\frac{E_{h_1}}{E_{h_2}} \approx \frac{Ch_1^{p}}{Ch_2^{p}} =\left(\frac{h_1}{h_2}\right)^{\!p},

eliminates the unknown constant. Taking logarithms gives the estimator

\boxed{\; p\approx \frac{\log\bigl(E_{h_1}/E_{h_2}\bigr)} {\log\bigl(h_1/h_2\bigr)}\;} \tag{2.2}

which for a halved step, h_2=h_1/2, reduces to p\approx\log_2\bigl(E_{h_1}/E_{h_2}\bigr).

Equivalently, taking logarithms in Equation 2.1,

\log E_h\approx\log C+p\log h,

so that plotting \log E_h against \log h gives a straight line of slope p and intercept \log C. Good linearity over several refinements is itself part of the verification: it confirms that the method is in its asymptotic regime.

A Worked Example

Consider the linear problem

y'=-2y+t^2, \qquad y(0)=\frac14,

whose exact solution is

y(t)=\frac{t(t-1)}{2}+\frac14+\left(y_0-\frac14\right)e^{-2t},

so that for y_0=\frac14 the exponential term disappears and the solution is the polynomial t(t-1)/2+1/4. The right-hand side still depends on y, so no method below reproduces it exactly — the test is a genuine one. We integrate on [0,1] with the explicit Euler, Heun and classical RK4 methods, halving the step size seven times.

f     <- function(y, t) -2 * y + t^2
exact <- function(t, y0) t * (t - 1) / 2 + 1/4 + exp(-2 * t) * (y0 - 1/4)

# generic explicit one-step driver: y_{k+1} = y_k + h * Psi(t_k, y_k, h)
one_step <- function(Psi, t0, y0, h, t_end) {
  t <- seq(t0, t_end, by = h)
  y <- numeric(length(t)); y[1] <- y0
  for (i in seq_len(length(t) - 1)) y[i + 1] <- y[i] + h * Psi(t[i], y[i], h)
  data.frame(t = t, y = y)
}

psi_euler <- function(t, y, h) f(y, t)
psi_heun  <- function(t, y, h) {
  k1 <- f(y, t); k2 <- f(y + h * k1, t + h); (k1 + k2) / 2
}
psi_rk4   <- function(t, y, h) {
  k1 <- f(y, t);           k2 <- f(y + h/2 * k1, t + h/2)
  k3 <- f(y + h/2 * k2, t + h/2); k4 <- f(y + h * k3, t + h)
  (k1 + 2*k2 + 2*k3 + k4) / 6
}

t0 <- 0; y0 <- 0.25; t_end <- 1
hs <- 0.1 / 2^(0:6)

max_error <- function(Psi) sapply(hs, function(h) {
  s <- one_step(Psi, t0, y0, h, t_end)
  max(abs(s$y - exact(s$t, y0)))
})

E <- data.frame(h     = hs,
                Euler = max_error(psi_euler),
                Heun  = max_error(psi_heun),
                RK4   = max_error(psi_rk4))

tabE <- E
tabE[-1] <- lapply(tabE[-1], formatC, format = "e", digits = 2)
tabE$h   <- formatC(E$h, format = "e", digits = 2)
knitr::kable(tabE, align = "r",
             col.names = c("$h$", "Euler", "Heun", "RK4"),
             caption = "Maximum error $E_h$ on $[0,1]$.")
Maximum error E_h on [0,1].
h Euler Heun RK4
1.00e-01 2.23e-02 2.40e-03 3.98e-06
5.00e-02 1.10e-02 5.69e-04 2.37e-07
2.50e-02 5.45e-03 1.39e-04 1.44e-08
1.25e-02 2.71e-03 3.42e-05 8.91e-10
6.25e-03 1.35e-03 8.50e-06 5.53e-11
3.13e-03 6.76e-04 2.12e-06 3.45e-12
1.56e-03 3.38e-04 5.29e-07 2.15e-13

The observed orders between consecutive refinements follow from Equation 2.2:

obs <- function(e) c(NA, log(head(e, -1) / tail(e, -1)) /
                         log(head(hs, -1) / tail(hs, -1)))
O <- data.frame(h = formatC(hs, format = "e", digits = 2),
                Euler = obs(E$Euler), Heun = obs(E$Heun), RK4 = obs(E$RK4))
knitr::kable(O, align = "r", digits = 3,
             col.names = c("$h$", "Euler", "Heun", "RK4"),
             caption = "Observed order between consecutive step sizes.")
Observed order between consecutive step sizes.
h Euler Heun RK4
1.00e-01 NA NA NA
5.00e-02 1.023 2.075 4.070
2.50e-02 1.011 2.037 4.036
1.25e-02 1.006 2.018 4.018
6.25e-03 1.003 2.009 4.009
3.13e-03 1.001 2.005 4.004
1.56e-03 1.001 2.002 4.003

The three columns converge to 1, 2 and 4, matching the theoretical orders. A single global estimate can also be obtained by least squares on the log-log data, which is what the slopes of the following plot represent.

long <- reshape2::melt(E, id.vars = "h",
                       variable.name = "method", value.name = "error")

ggplot2::ggplot(long, ggplot2::aes(h, error, colour = method)) +
  ggplot2::geom_line() + ggplot2::geom_point() +
  ggplot2::scale_x_log10() + ggplot2::scale_y_log10() +
  ggplot2::labs(x = "h", y = expression(E[h]), colour = "method") +
  ggplot2::theme_minimal()
Figure 2.1: Maximum error versus step size in logarithmic scale. The slopes are the observed orders.
WarningHow to read an order verification
  • Look for a plateau, not a single number. Three or four consecutive estimates settling on the same value are evidence; one value is not.
  • Stay in the useful window. The estimate is meaningful only when h is small enough for the asymptotic regime Equation 2.1 to hold, and large enough that E_h is well above the rounding level \sim\varepsilon_{\rm mach}. For a fourth-order method on a smooth problem this window can be only two or three refinements wide, which is why the verification should be run with a loose tolerance rather than at the limit of machine precision.
  • A wrong order is informative. An observed order of 1 for a method designed to be of order 2 usually means a misplaced h in the increment function; an observed order one higher than expected usually means the test problem is too special — a polynomial solution, for instance, can be integrated exactly by a method of sufficient order.
  • Without an exact solution, replace y(t_k) by a reference computed on a much finer mesh, or use the three-mesh estimator p\approx\log_2\bigl|(y^{4h}-y^{2h})/(y^{2h}-y^{h})\bigr|, which needs no exact solution at all.

Summary

  • A one-step method is written y_{k+1}=y_k+h\Psi(t_k,y_k;h); the whole theory relates the local defect \mathcal O(h^{p+1}) to the global error \mathcal O(h^{p}).
  • The convergence theorem Theorem 2.1 gives the explicit bound \frac{C}{L_\Psi}\bigl(e^{L_\Psi(t_k-t_0)}-1\bigr)h^{p}: the Lipschitz property of f is the only substantial hypothesis.
  • Explicit Euler has order 1; Heun and Collatz reach order 2 with two evaluations of f per step.
  • Implicit Euler and Crank–Nicolson require solving an equation at every step but have far better stability properties.
  • The order is verified numerically from the ratio of errors at halved step sizes, Equation 2.2 — a check that should accompany every implementation.