From first principles
Follow one local error through the remaining steps
An initial-value problem specifies a rate \(y'=f(t,y)\) and a starting value. Integrating the rate over a short interval gives the exact change. Approximating the integrand by the rate at the left endpoint is forward Euler. Suppose the solution is twice differentiable with \(\lVert y''\rVert\le M\). Taylor’s theorem bounds the defect made by a single step starting at the exact value:
The next step generally starts at a computed value \(y_n\). If changing the input state changes the rate by at most \(L\) times that change in norm, then for \(e_n=y(t_n)-y_n\) subtraction gives
Each earlier defect can therefore be amplified by every later step. With exact initial data, sum the resulting geometric series up to fixed time \(T=nh\), for \(L>0\):
The local \(h^2\) becomes global \(h\) because the number of terms grows on refinement. When \(L=0\), their sum is \(MTh/2\). An uncertain initial value contributes a separate amplified initial-error term.
Background · Local truncation error
This is the one-step defect from exact starting data. Some conventions divide it by h. State the convention before comparing local and global orders.
Derivation and applications
Estimate an endpoint error from two grids that share the same endpoint
A local defect need not equal the error in a reported final state. A practical test for a smooth nonstiff initial-value problem is to integrate to the identical physical time on two or more nested time grids. Suppose the method has global order \(p\) and its leading error varies smoothly with step size. Write \(Y_h\) for its value at the final time and \(y\) for the exact value there. The asymptotic expansion and its version on the refined grid are
Here \(C\) depends on the problem and final time but is common to these two runs. Subtract to estimate the error of the fine result. The sign convention below is correction to the fine result, not numerical value minus exact value:
A third grid can test whether the nominal \(p\) applies. The unknown coefficient cancels in the ratio of successive differences:
If two differences have incompatible signs or are close to roundoff, this diagnostic becomes unreliable. A nonsmooth switch, an approximate event location or comparing different physical final times can also destroy the shared expansion. The estimate concerns the specific endpoint output; a zero leading error there need not indicate higher order throughout the trajectory.
Worked example
Extrapolate a smooth decay calculation
For \(y'=-y\), \(y(0)=1\), integrate to \(t=1\) with Euler steps \(h=1/4\) and \(1/8\). The endpoint values are
For \(p=1\) the fine estimate needs a positive correction of \(0.027203\), giving \(Y_{\rm ext}=0.370812\). The exact value \(e^{-1}=0.367879\) lies much closer to the extrapolation than either raw value. Extrapolation removes the leading bias but does not make an exact solution.
Second application
Check the order before trusting an error bar
A different endpoint measurement returns \(1.2480\), \(1.2120\) and \(1.2030\) on successive halvings. Their differences are \(0.0360\) and \(0.0090\), yielding \(p_{\rm obs}=2.00\). The finest correction is \(-0.0090/(4-1)=-0.0030\), so the extrapolated endpoint is \(1.2000\). Using a first-order denominator would triple the estimated correction.
OneSimulation laboratory
Compare time-step error with conservation
Start from this chapter. For a scalar exponential decay, the exact one-step amplification is known. Accumulate the numerical factor to predict the final concentration, then check a separate conserved sum.
Compare recorded OneSimulation runs on this page. To test your own inputs, download the Python model and run the model in an activated OneSimulation environment.
Run the isothermal reaction from \(A=1,\ B=0\) mol/m³ to \(t=5/k=6.25\) s. Measure the maximum A error over all stored times and the drift of \(A+B\). First double the number of RK4 steps. Then restore 100 steps and change the time integrator. Download the Python experiment · OneSimulation first-order decay model.
python ordinary-differential-equations.py
python ordinary-differential-equations.py --steps 200
python ordinary-differential-equations.py --method euler
| Method, steps | Final A (mol/m³) | Max. A error (mol/m³) | Max. drift (mol/m³) |
|---|---|---|---|
| RK4, 100 | 0.00673794883 | 2.00 × 10⁻⁸ | 4.44 × 10⁻¹⁶ |
| RK4, 200 | 0.00673794711 | 1.22 × 10⁻⁹ | 3.33 × 10⁻¹⁶ |
| Euler, 100 | 0.00592052922 | 9.39 × 10⁻³ | 4.44 × 10⁻¹⁶ |

As a fourth run, try --method euler --steps 5. This lands exactly on the nonnegativity limit. Predict both the final concentration and the largest error before running it.
Change parameters · Change the laboratory inputs
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.
Problem sheet 1 · Predict when a conservative calculation loses all reactant
Specify what the trajectory represents
In an initial-value problem \(y'=f(t,y)\), \(y(t_0)=y_0\), the time history follows from both the law and the initial state. A measurement made up to an absolute uncertainty gives a family of possible trajectories even before selecting a method. A numerical calculation adds further deviations each time it replaces the continuous flow over a short interval by an algebraic update. To estimate the final error, track how deviations arising early in a run are transported through later steps.
If \(f\) is continuous in time and locally Lipschitz in the state, the initial-value problem has a unique local solution. Lipschitz continuity is more than a technical detail. For \(y'=2\sqrt{|y|}\) with \(y(0)=0\), solutions may remain zero up to any chosen nonnegative time \(c\) and then follow \((t-c)^2\). Continuity alone gives no unique departure time. A code that keeps returning zero is computing one admissible trajectory, but there is no single exact departure trajectory against which to grade it without further modelling information.
Accumulate one-step errors
Write the exact integral from \(t_n\) to \(t_n+h\). Approximating the integrand by its value at the start gives
Inserting an exact smooth solution in this update produces a one-step defect bounded by \(Mh^2/2\), where \(M\) bounds \(|y''|\) over the interval. This defect starts a step from the exact state. Actual steps generally start from an already perturbed state.
Let \(e_n=|y(t_n)-y_n|\), with state Lipschitz bound \(L\). Adding and subtracting a step started at the exact value gives
Iterate this inequality as a geometric series. For \(L>0\) and elapsed time \(T=nh\), use \((1+hL)^n\leq e^{LT}\) to conclude
For \(L=0\) the second term becomes \(MTh/2\). A local error of order two gives order one over fixed time, while the initial uncertainty contributes separately. The bound treats every perturbation as if amplified. A dissipative system may damp them strongly, so a more problem-specific calculation can be much sharper.
Background · Which direction does an earlier local error take?
For the two-component system \(y'=Ay\), an additive state error introduced at time \(t_j\) contributes \(e^{A(T-t_j)}d_j\) to the endpoint. A norm estimate counts the magnitudes of those contributions. Their directions can reinforce or cancel. For undamped rotation at angular speed \(\omega\), equal displacement errors introduced half a period apart reach the endpoint in opposite directions and cancel exactly.
This is why error bounds add absolute contributions while an experiment can show a much smaller final error. A single endpoint near cancellation gives a poor estimate of an integration method’s order. Check errors at more than one observation time, or use a maximum-in-time norm, when the quantity of interest covers the entire path.
Test the prediction against exact exponential growth
Take \(y'=y,\ y(0)=1\) over one time unit. Forward Euler with two steps gives \(1.5^2=2.25\); with four it gives
The exact result is \(e=2.71828\). The errors 0.46828 and 0.27688 decrease by a factor about 1.69. The limiting factor of two requires a finer asymptotic regime. Expanding \(N\log(1+1/N)=1-1/(2N)+O(N^{-2})\) predicts \(e-(1+1/N)^N=e/(2N)+O(N^{-2})\).
If the initial value is actually 1.01, its exact trajectory at time one differs from the nominal one by \(0.01e\). Mesh refinement of the nominal solver cannot decide which initial reading is correct. To evaluate an integration scheme experimentally, fix the model and initial data, compare at a common endpoint and record the norm used. Resampling a coarse trajectory at extra plot positions changes the reported curve but does not alter the integration error accumulated at its original nodes.
Use a manufactured trajectory to test a solver
Instead of relying on a familiar unforced exponential, choose an exact function and derive the source that produces it. For \(y'+2y=s(t)\), selecting \(y_\star=1+\sin t\) requires \(s=\cos t+2(1+\sin t)\) and \(y(0)=1\). The forcing and damping are both active. A solver that silently evaluates the source at the wrong stage time can pass constant-source tests but fail this one.
Over one Euler step of 0.2 the initial derivative is one, so \(y_1=1.2\) versus the exact \(1+\sin(0.2)=1.19867\). This small first-step discrepancy is unusually favourable because \(y_\star''(0)=0\). It does not imply the global method has become second order. Report an error over a fixed time interval with multiple nontrivial phases of the forcing. A single specially located sample can suppress the leading contribution and give a misleading estimate.
Measure the defect of an entire reconstructed trajectory
Suppose a time integrator supplies a differentiable curve \(U(t)\) between its stored nodes. Its continuous defect is \(d(t)=U'(t)-f(t,U(t))\), the forcing that would make the reconstructed curve satisfy a perturbed differential equation exactly. For a scalar linear equation \(y'=a(t)y+b(t)\), the state error \(e=U-y\) satisfies
Multiplication by an integrating factor gives the exact identity
This equation distinguishes defects by when they occur. In a dissipative equation with \(a\le-\alpha<0\), older defects receive exponentially smaller weights. If \(|d|\le D\), the resulting bound is \(e^{-\alpha T}|e(0)|+D(1-e^{-\alpha T})/\alpha\). Simply multiplying the worst defect by the duration misses this damping. For a growing mode the weighting reverses: even a modest defect introduced early can dominate the final state. A defect must be examined between nodes; sampling only locations where a collocation method enforces the equation can return zero by construction.
Check a polynomial approximation to a driven relaxation
Take \(y'=-2y+t,\ y(0)=0\), and on \([0,1]\) use the approximate curve \(U(t)=t^2/2\), obtained by integrating the input while ignoring damping. Then \(U'=t\), while the actual right-hand side at \(U\) is \(t-t^2\). The defect is \(d(t)=t^2\), zero initially and largest at the final time. Its sign shows that the approximate curve is receiving an artificial positive input. The crude bound with \(D=1,\alpha=2\) gives final error at most \((1-e^{-2})/2\approx0.4323\), already tighter than the undamped bound of one.
Solve the true equation with an integrating factor:
At the endpoint the error is
Independently integrating the defect with the correct damping weight gives \(\int_0^1 e^{-2(1-s)}s^2ds=(1-e^{-2})/4\), exactly reproducing it. The difference between the two estimates has an interpretation: the simpler bound assumed the worst defect was present throughout, while the actual curve develops most of its error only near the end.
One can even use the defect to form a correction by solving the linear error equation and subtracting the estimated error from \(U\). For a nonlinear problem linearising around the reconstructed path introduces a new remainder and the correction is no longer exact. Still, it targets the right mechanism: identify where the reconstructed curve fails the original equation and propagate that imbalance to the particular observation time instead of judging a trajectory only by its nodal appearance.
The same forcing identity can distinguish two curves passing through identical initial and final data. One curve may solve the differential equation nearly everywhere, while another contains positive and negative defects whose weighted integrals cancel exactly at the final time. If the experiment also observes a midpoint, that cancellation no longer guarantees agreement there. A dense-output validation should therefore compare defect over the full interval and state error at the actual observation times, especially when a numerical interpolant is used for later event finding.
Propagate a persistent local defect through an evolution
Model the accumulation of small local errors by \(e'=\lambda e+1,\ e(0)=0\). Variation of constants integrates each earlier defect with weight \(e^{\lambda(t-s)}\). Compare a contracting flow, a neutral direction and an unstable direction.

Read values from the plot
| Time | Growth rate -1 | Growth rate +0 | Growth rate +0.6 |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1.24 | 0.71062 | 1.24 | 1.8406 |
| 2.5 | 0.91792 | 2.5 | 5.8028 |
| 3.76 | 0.97672 | 3.76 | 14.241 |
| 5 | 0.99326 | 5 | 31.809 |
Change parameters · Propagate a persistent local defect through an evolution
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.
Study the full derivation
Find a crossing between accepted time steps · Dynamics and numerical time integration
An integrator can approximate a trajectory accurately yet report a poor switch time. Construct a continuous interpolant, relate a state error to an event-time error and inspect what happens when a trajectory merely touches a threshold.