Method
Integrators for ODEs
Adapted
Builds the one-step and multistep integrators for from the Taylor expansion they imitate, defines the local truncation error and the order, proves that a method of order whose increment is Lipschitz has global error at most , and verifies the orders , , and of Euler, Heun, Adams-Bashforth and classical Runge-Kutta on a nonlinear problem with a known solution.
Prerequisites: Existence and uniqueness of solutions, Taylor's theorem, Dependence on initial data and Gronwall's inequality, Linear systems and the matrix exponential
Throughout, the object to be solved is the initial-value problem
on an interval , where may be a vector in and is defined on a region . By Existence and uniqueness of solutions a unique solution exists as long as is continuous and Lipschitz in , and that is the function the methods below try to produce. Nothing is lost by restricting attention to first-order systems: an equation becomes the system in the unknowns , and every method here is applied componentwise, all components being advanced through a step before any is advanced through the next. Riley, Hobson and Bence set this reduction out in full; it is the first thing done to a high-order equation before it is handed to software, and it is the reason the units on linear systems (Linear systems and the matrix exponential) and on integrators speak the same language.
Fix a step size and the grid . The methods produce numbers intended to approximate ; is a vector when is.
A one-step method is a rule
in which the increment function is built from evaluations of alone. The method is explicit when can be evaluated from by a finite list of substitutions, as all the methods in this unit can; methods for which appears on both sides are implicit and are the subject of Stability and stiff equations.
A linear multistep method with steps is a rule
with constant coefficients; it is explicit when . Such a method needs starting values, and only one of them is given by the problem.
Let denote the exact solution. The local truncation error of a one-step method at is the amount by which the exact solution fails to satisfy the method's own recurrence over one step:
It is the error a single step would commit if it started from exact data. The method has order on if there is a constant , independent of and , with
and if is the largest exponent for which this holds. A method of order is consistent: dividing by , the recurrence reproduces the differential equation in the limit.
The global error is , the quantity the user actually suffers. The method converges if as with fixed. The one power of that separates from the global error is the bookkeeping of the theorem below: roughly local errors of size accumulate into a global error of size .
For a multistep method the local truncation error is defined by the same substitution of the exact solution into the recurrence, and the order is again the largest with .
Write . Each rule below says which slope is used to cross the interval ; Hirsch, Smale and Devaney's way of putting it is that a method is nothing but a choice of the straight line along which the step is taken.
Euler's method uses the slope at the left endpoint:
Strogatz reads it off the vector field directly: travel for time at the velocity found where you are.
The improved Euler (Heun) method takes a trial step with Euler, evaluates the slope there, and crosses with the average of the two slopes:
The midpoint method instead uses a half-step probe and crosses with the slope found there:
The classical fourth-order Runge-Kutta method (RK4) uses four slopes:
The two-step Adams-Bashforth method (AB2) is not a one-step method: it reuses the slope already computed at the previous grid point,
Riley, Hobson and Bence derive it by fitting a straight line to through the two points and and integrating that line across ; the extra term is a correction to the Euler step. It costs one evaluation of per step, against two for Heun and the midpoint rule and four for RK4, because is kept from the previous step.
1 (Convergence). Let with , let the exact solution of , stay in on , and consider a one-step method started exactly, , whose iterates also stay in . Suppose
- (L) the increment function satisfies for all and all , with ; and
- (T) the local truncation error obeys on for .
Then for every and every grid point ,
In particular the method converges, with global error : one power of is lost relative to the local error.
2 (Orders). Let be as smooth as each statement requires on a neighbourhood of the solution. Then
- Euler's method has order , with local truncation error ;
- the Heun and midpoint methods have order ;
- AB2 has order , with local truncation error ;
- RK4 has order .
3 (The second-order family). Every method of the two-stage form
has order at least if and only if
so the family has one free parameter. Heun is , ; the midpoint method is , , . No member of the family has order for all .
Every method here is an attempt to imitate the Taylor expansion of the exact solution without differentiating . The expansion needs , , and so on; computing those by hand is exactly what Runge-Kutta methods avoid, by evaluating itself at cleverly placed points and combining the values so that the combination reproduces the Taylor coefficients. Matching through is what "order " means, and part 3 shows the matching conditions in the smallest nontrivial case.
The convergence statement is an accumulation argument with one twist. Over a step, the previous error is carried forward and distorted by the method, and a fresh local error is added. Hypothesis (L) says the distortion is at worst a factor , so the errors obey . The twist is that summing this geometric recursion produces , and the factor in the denominator cancels one power of from the numerator ; that is where the lost power goes. Finally converts the discrete growth factor into the exponential that Gronwall's inequality produces for the continuous problem. The exponential is not an artefact: two exact solutions of the same equation really can separate that fast, so no method can do better.
Step 1 (one step of the recursion). Write and . By the definition of the local truncation error applied at ,
while the method gives . Subtracting,
Step 2 (estimate it). Both and lie in , by the hypothesis that the exact solution and the iterates stay there. So hypothesis (L) bounds the bracket by , and hypothesis (T) bounds by . The triangle inequality gives
Step 3 (an accumulation lemma). If and holds with and , then . Induct on . The case reads , which is the hypothesis. If the bound holds at then
which is the bound at .
Step 4 (substitute and simplify). Here , so
The single power of cancelled against is the one lost between local and global order.
Step 5 (exponential form). For the convexity of the exponential gives , so because . Substituting into Step 4 gives the claim. The starting value is exact, , as assumed in Step 3; if instead the same induction yields the extra term .
Throughout, is the exact solution through , so that , and all derivatives are evaluated at unless marked otherwise. We use the chain rule in the form Riley, Hobson and Bence record, , and Taylor's theorem (Taylor's theorem).
Euler. With ,
which is and no better unless . So .
The two-stage family, and Heun and midpoint with it. Expand the second stage of the family in part 3 of the statement by Taylor's theorem in two variables, about :
Hence the increment is
The exact increment is . Matching the and terms gives exactly the two conditions and , and these are necessary as well as sufficient because and the combination can be prescribed independently at a point. Heun and the midpoint method satisfy them, so both have order at least .
For the last sentence of part 3, carry the expansion one term further. The coefficient produced by the family is
while the exact solution has . The second group, , cannot be produced at all: no choice of puts a term containing into the coefficient. So the family never reaches order , and two stages are genuinely not enough. (This is where the extra stages of RK4 earn their keep.)
AB2. Substituting the exact solution, and writing ,
Subtracting this from , the first two terms cancel and
so AB2 has order with the error constant .
Matching the Taylor expansion through imposes the eight order conditions through order on the coefficients of a four-stage Runge-Kutta method, and verifying them by hand is several pages of bookkeeping with no idea in it. Riley, Hobson and Bence print the scheme "without derivation" for the same reason, and Strogatz calls the four numbers cunningly chosen and leaves their choice to an exercise. We follow them in stating the order rather than deriving it, and verify it in two independent ways instead.
Symbolically. Expanding and the exact solution in powers of with computer algebra, for the non-autonomous field
at , the two series agree through and first differ at , with coefficient . The same computation returns leading powers for Euler, for Heun and for the midpoint rule, and for the third-order scheme Riley, Hobson and Bence give as their Eq. (27.79) — that is, orders , , and , confirming the hand derivations above and showing that this particular is generic enough to detect the true order.
Numerically. The error table in the first example below halves the step four times and shows the RK4 error falling by factors tending to , which is the signature of order .
(L), the Lipschitz condition on , is what makes errors merely grow exponentially instead of arbitrarily. It is inherited from : for Euler, , so (L) is the Lipschitz condition of Existence and uniqueness of solutions itself. For a multi-stage method each stage is a Lipschitz function of the previous one, so if has Lipschitz constant in on then has a Lipschitz constant of the form , bounded by a constant multiple of for . Without (L) the recursion in Step 2 has nothing to bound the propagated error by: the first stage of the proof fails immediately, not just the constant.
(T) must be uniform in . The constant involves derivatives of the solution, through , and so on. On an interval where the solution approaches a singularity these blow up, and the bound is true but empty. The example below is deliberately set on for this reason: its exact solution has a pole at , and the error constants degrade badly as that point is approached.
The iterates must stay in . This is a hypothesis, not a conclusion, and it is the one that is usually verified after the fact. It can genuinely fail: for , , whose solution blows up at , an Euler step from near the pole lands far outside any region on which a Lipschitz constant was computed. In practice one integrates, checks that the computed track stayed inside the region used to compute , and reruns with a smaller step if not.
Order is a statement about smooth . Each order calculation differentiates as many times as the expansion requires: order needs near the solution. Applied to an with a kink — a switch in a control law, a table lookup, a friction law that changes form at zero velocity — RK4 is not fourth order across the kink, and refining the step buys much less than the table of ratios would suggest. The standard remedy is to stop the integration at the discontinuity and restart.
The exponential factor is sharp. Taking makes exactly -Lipschitz, and two exact solutions separate by precisely times their initial gap. So no sharper general bound than part 1 exists, and the is what makes long integrations of systems with positive Lyapunov exponents (Lyapunov exponents and sensitive dependence) untrustworthy trajectory by trajectory.
Round-off sets a floor that the theorem does not see. Part 1 says the error decreases like forever, which is false in floating-point arithmetic: each of the steps commits a rounding error of relative size about the unit roundoff (Floating-point arithmetic and error), and these accumulate roughly as , growing as shrinks. The total error is therefore U-shaped in , with a minimum near . Strogatz makes exactly this point when he warns against simply choosing a tiny step and leaving it there.
- Reduce to a first-order system. Introduce as in the first definition, so the problem becomes with . Advance all components through each step before starting the next.
- Non-dimensionalise. Scale and each component of so that the quantities of interest are of order one. Step-size choices, error tolerances and the convergence table all become meaningful only after this.
- Estimate the two constants. Compute over the region you expect to visit; this gives the Lipschitz constant and the factor that no method can avoid. If is astronomically large, no accuracy target is achievable and the question being asked of the computation should change.
- Choose the method by the cost of . Count evaluations per step: for Euler and AB2, for Heun and midpoint, for RK4. When is expensive and the solution is smooth, the higher order wins easily, because reaching a tolerance needs and so steps.
- Start a multistep method with a one-step method of at least the same order. AB2 needs as well as ; take it from one RK4 step, whose error cannot pollute an computation. Riley, Hobson and Bence note the same need for the central-difference and Adams schemes and suggest a Taylor expansion; a Runge-Kutta step is the modern answer and needs no derivatives of .
- Measure the order, do not assume it. Run at , , and tabulate the differences of the answers. Successive differences falling by confirm the order and simultaneously confirm that the solution is smooth enough for it.
- Control the step by step doubling. Take one step of size and two of size from the same point. For a method of order the difference of the two answers is about times the error of the finer one — equivalently times the error of the coarser one — so the finer answer carries an error of about , which is for RK4; that is an error estimate for free; accept the step if it is below tolerance, and set the next step to with a safety factor of about . Richardson extrapolation can also be used to improve the answer, at the price of losing the error estimate.
- Predict and correct, if the method is implicit. Riley, Hobson and Bence's pattern — predict with an explicit formula, evaluate there, then recompute with the better formula — is the cheap way to use an implicit formula without solving an equation. Iterating the correction converges only when times the Lipschitz constant is small, which is precisely what fails for the stiff problems of Stability and stiff equations; there the corrector must be solved properly, by Newton's method (Root finding).
- Check a conserved quantity if the problem has one. A drift in the energy of a mechanical system is the clearest diagnostic there is, and for long integrations it is a reason to change the class of method entirely (Symplectic integrators).
Take
whose solution is found by separation: with , so
valid up to the pole at . We integrate to , where . All arithmetic below was done in -digit precision so that nothing reported is round-off.
One step by hand, . Here , so Euler gives . For RK4,
and . The exact value is . The three errors after one step are
in the ratio — already the , , hierarchy of local errors at a single step size.
Global errors at . Each column gives the error and, beneath, the factor by which it shrinks when is halved. AB2 was started with one RK4 step, as step 5 of the method recommends; the column depends on that choice, and a cruder start changes its leading digits.
| Euler | Heun | midpoint | AB2 | RK4 | |
|---|---|---|---|---|---|
| ratios |
The five columns converge to the factors , , , and , confirming orders , , , and . Heun and the midpoint rule, the two members of the family of part 3 that we singled out, cost the same and differ only in their error constants: against , so on this problem Heun's error is smaller by about at a fixed step. Since the error goes as , that buys only a larger step at a given tolerance, which is no reason to prefer one over the other. AB2 approaches its asymptotic factor more slowly than Heun, as a two-step method with a larger error constant should: at its error is times Heun's, although both are second order.
Cost at a fixed accuracy. Read an error constant off the finest row, : it is for Euler, for Heun and for RK4. Solving and dividing by the result gives
| method | for | steps | evaluations of |
|---|---|---|---|
| Euler | |||
| Heun | |||
| RK4 |
So RK4 costs about times fewer evaluations than Euler here and about times fewer than Heun, and both advantages grow without limit as the tolerance tightens: the evaluation count scales as for Euler, for Heun and for RK4.
The convergence bound, checked. Take the region , which contains both the exact solution and every Euler iterate computed above (the largest over all six runs is , at the finest step; at it is ). On , , so serves for Euler, whose is . The local error constant is , and increases on from to , so . Part 1 then predicts
At this is against the measured , at it is against , and at it is against . The bound holds with a factor of between and to spare, and the slack has the expected cause: it assumes the worst case at every step, whereas starts at and only reaches at , climbing through at and at before its final ; and it assumes the error is amplified at the maximal rate throughout.
Every simulation of a continuous system is an instance of this. The equations of a spacecraft trajectory, a reaction network, a power-system transient, a population model or a climate model's physics column are first-order systems after the reduction above, and all of them are advanced by one of the methods here or a descendant.
Why RK4 and not something better. A production solver is usually an embedded Runge-Kutta pair — two methods of adjacent order sharing their stage evaluations, so that the difference of the two answers is an error estimate at almost no extra cost, which drives the step-size controller of step 7. The classical RK4 survives because it is the cheapest scheme whose order is high enough that smooth problems are limited by round-off rather than truncation at a comfortable step size, and because its four stages map cleanly onto a force routine that is called once per stage.
Where order is the wrong figure of merit. Two situations in this chapter defeat the analysis above, and each has its own unit. A system with widely separated time scales forces the step far below what accuracy needs, because an explicit method becomes unstable long before it becomes inaccurate; the diagnosis and the implicit cure are in Stability and stiff equations. A Hamiltonian system integrated over millions of periods suffers a slow drift in its energy that no increase of order removes, because the drift is a structural defect rather than a truncation error; the remedy, a method that is exactly symplectic at every step, is in Symplectic integrators.
Method of lines. Discretising a partial differential equation in space alone (Finite-difference approximations, Spectral methods) leaves a large system of ordinary differential equations in time, to which the methods here apply directly. This is how most time-dependent PDE codes are organised, and it is why the stability restrictions of Stability, the CFL condition and von Neumann analysis and the stiffness of Stability and stiff equations are two views of a single phenomenon: the eigenvalues of the spatial discretisation grow like for a diffusion operator, and the explicit integrator's step must shrink to match.