Why is RK4 fourth-order accurate?
Environment
Python 3.14.6, NumPy 2.5.4, SymPy 1.14.0, Matplotlib 3.11.2.
This article is a rewrite of a post from around 2013–2016, with calculations performed in the environment described above.
Overview
We explain why classical four-stage Runge–Kutta, RK4, is fourth-order accurate by comparing Taylor expansions of the exact solution and each stage. We derive the one-step error $O(h^5)$ and fixed-interval error $O(h^4)$, then check convergence orders in Python. The examples include linear, nonlinear, and coupled equations.
Setup
Run the code in Jupyter Notebook from top to bottom.
Imports and plotting setup
import platform
from pathlib import Path
from pprint import pprint
import numpy as np
import sympy as sp
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter, NullFormatter
from IPython.display import Latex, display
%matplotlib inline
from matplotlib_inline.backend_inline import set_matplotlib_formats
# Save figures as SVG and also embed PNG for notebook viewer compatibility.
set_matplotlib_formats("svg", "png")
assert platform.python_version() == "3.14.6"
print("Environment: wa-src(3.14.6)")
print("Python:", platform.python_version())
for package in (np, sp, matplotlib):
print(package.__name__, package.__version__)
image_dir = Path("106_nb_files")
image_dir.mkdir(exist_ok=True)
plt.rcParams.update({"font.size": 11, "figure.figsize": (10, 4)})
def sig3(value):
"""Use three significant digits for display only."""
if value == 0:
return "0"
if abs(value) < 0.0100 or abs(value) >= 1000:
return f"{value:.2e}"
return f"{float(value):#.3g}".removesuffix(".")
np.set_printoptions(formatter={"float_kind": sig3})
def save_plot(fig, name):
"""Format ticks and use the same figure for SVG saving and notebook display."""
for ax in fig.axes:
ax.grid(alpha=0.300)
for axis in (ax.xaxis, ax.yaxis):
axis.set_major_formatter(FuncFormatter(lambda x, pos: sig3(x)))
axis.set_minor_formatter(NullFormatter())
fig.tight_layout()
fig.savefig(image_dir / f"{name}.svg", format="svg")
plt.show()
plt.close(fig)
Environment: wa-src(3.14.6)
Python: 3.14.6
numpy 2.5.4
sympy 1.14.0
matplotlib 3.11.2
1. The RK4 update
Solve the initial-value problem $\mathbf y^{\prime}=\mathbf f(t,\mathbf y)$ with step size $h$. The value $\mathbf y_n$ approximates the solution at $t_n$, and each $\mathbf k_i$ is a slope. We do not include $h$ in $\mathbf k_i$.
$$ \begin{aligned} \mathbf k_1&=\mathbf f(t_n,\mathbf y_n),\\ \mathbf k_2&=\mathbf f(t_n+h/2,\mathbf y_n+h\mathbf k_1/2),\\ \mathbf k_3&=\mathbf f(t_n+h/2,\mathbf y_n+h\mathbf k_2/2),\\ \mathbf k_4&=\mathbf f(t_n+h,\mathbf y_n+h\mathbf k_3),\\ \mathbf y_{n+1}&=\mathbf y_n+\frac h6(\mathbf k_1+2\mathbf k_2+2\mathbf k_3+\mathbf k_4). \end{aligned} $$
Two stages evaluate the midpoint time, but they use different states. Four evaluations alone do not give fourth-order accuracy; their locations and weights matter. We also implement Euler and explicit midpoint, RK2, for comparison.
def rk4_stages(f, t, y, h):
"""Compute four slopes in sequence, supporting scalars and arrays."""
k1 = f(t, y)
k2 = f(t + h / 2, y + h * k1 / 2)
k3 = f(t + h / 2, y + h * k2 / 2)
k4 = f(t + h, y + h * k3)
return k1, k2, k3, k4
def rk4(f, t, y, h):
k1, k2, k3, k4 = rk4_stages(f, t, y, h)
return y + h * (k1 + 2 * k2 + 2 * k3 + k4) / 6
def euler(f, t, y, h):
return y + h * f(t, y)
def midpoint(f, t, y, h):
return y + h * f(t + h / 2, y + h * f(t, y) / 2)
def solve(step, f, y0, end, n):
"""Divide the interval from zero to end into n equal steps."""
t = np.linspace(0, end, n + 1)
y0 = np.asarray(y0, dtype=float)
y = np.empty((n + 1,) + y0.shape)
y[0] = y0
h = end / n
for i in range(n):
y[i + 1] = step(f, t[i], y[i], h)
return t, y
The exact solution of $y^{\prime}=y^2,\ y(0)=1$ is $y(t)=1/(1-t)$. Plot one step with $h=0.400$. The short segments show slopes at the evaluation points, which need not lie on the exact solution.
h = 0.400
f_stage = lambda t, y: y**2
k = rk4_stages(f_stage, 0, 1, h)
points = [(0, 1), (h / 2, 1 + h * k[0] / 2),
(h / 2, 1 + h * k[1] / 2), (h, 1 + h * k[2])]
pprint({f"k{i}": sig3(value) for i, value in enumerate(k, 1)})
fig, ax = plt.subplots()
t = np.linspace(0, h, 200)
ax.plot(t, 1 / (1 - t), color="black", label="Exact")
for i, ((ti, yi), ki) in enumerate(zip(points, k), 1):
dt = np.array([-1, 1]) * h / 16
ax.plot(ti + dt, yi + ki * dt, label=f"k{i}")
ax.scatter(ti, yi, s=30)
ax.scatter(h, rk4(f_stage, 0, 1, h), marker="x", label="RK4 endpoint")
ax.set(xlabel="t", ylabel="y", title="Four stage evaluations")
ax.legend(ncol=3)
save_plot(fig, "01_stages")
{'k1': '1.00', 'k2': '1.44', 'k3': '1.66', 'k4': '2.77'}
2. Expanding the exact solution through fourth order
Start with an autonomous system $\mathbf y^{\prime}=\mathbf F(\mathbf y)$. A time-dependent problem can be written in the same form by setting
$$ \mathbf z=\begin{pmatrix}t\\\mathbf y\end{pmatrix},\qquad \mathbf z^{\prime}=\begin{pmatrix}1\\\mathbf f(t,\mathbf y)\end{pmatrix} $$
The stage times also advance by $0,h/2,h/2,h$ in RK4, so the following argument applies.
Assume $\mathbf F$ is sufficiently smooth near the solution and that the required derivatives are bounded. Evaluate all quantities below at the start of the step.
$$ \mathbf g=\mathbf F(\mathbf y),\quad \mathbf J=D\mathbf F(\mathbf y),\quad \mathcal H=D^2\mathbf F(\mathbf y),\quad \mathcal T=D^3\mathbf F(\mathbf y). $$
$\mathbf J$ is the Jacobian, while $\mathcal H$ and $\mathcal T$ are multilinear maps taking two and three vectors, respectively. For example, component $i$ of $\mathcal H(\mathbf u,\mathbf v)$ is $\sum_{j,k}\partial_{jk}F_i\,u_jv_k$. The product and chain rules give
$$ \begin{aligned} \mathbf y^{\prime}&=\mathbf g,\\ \mathbf y^{\prime\prime}&=\mathbf J\mathbf g,\\ \mathbf y^{(3)}&=\mathcal H(\mathbf g,\mathbf g)+\mathbf J^2\mathbf g,\\ \frac{d}{dt}\mathcal H(\mathbf g,\mathbf g) &=\mathcal T(\mathbf g,\mathbf g,\mathbf g)+2\mathcal H(\mathbf g,\mathbf J\mathbf g),\\ \frac{d}{dt}(\mathbf J^2\mathbf g) &=\mathcal H(\mathbf g,\mathbf J\mathbf g) +\mathbf J\mathcal H(\mathbf g,\mathbf g)+\mathbf J^3\mathbf g. \end{aligned} $$
Add the last two lines to obtain $\mathbf y^{(4)}$, then substitute into the Taylor expansion.
$$ \begin{aligned} \mathbf y(t+h)={}&\mathbf y+h\mathbf g+\frac{h^2}{2}\mathbf J\mathbf g\\ &+\frac{h^3}{6}\{\mathcal H(\mathbf g,\mathbf g)+\mathbf J^2\mathbf g\}\\ &+\frac{h^4}{24}\{\mathcal T(\mathbf g,\mathbf g,\mathbf g) +3\mathcal H(\mathbf g,\mathbf J\mathbf g)\\ &\hspace{22mm}+\mathbf J\mathcal H(\mathbf g,\mathbf g)+\mathbf J^3\mathbf g\}+O(h^5). \end{aligned} $$
3. Expanding the RK4 stages
Write the change in state as $\mathbf d$. The function itself expands as follows.
$$ \mathbf F(\mathbf y+\mathbf d)=\mathbf g+\mathbf J\mathbf d +\frac12\mathcal H(\mathbf d,\mathbf d) +\frac16\mathcal T(\mathbf d,\mathbf d,\mathbf d)+O(\|\mathbf d\|^4). $$
Substituting $\mathbf d_2=h\mathbf g/2$ gives the second stage.
$$ \mathbf k_2=\mathbf g+\frac h2\mathbf J\mathbf g +\frac{h^2}{8}\mathcal H(\mathbf g,\mathbf g) +\frac{h^3}{48}\mathcal T(\mathbf g,\mathbf g,\mathbf g)+O(h^4). $$
For the third stage, $\mathbf d_3=h\mathbf k_2/2$, so
$$ \mathbf d_3=\frac h2\mathbf g+\frac{h^2}{4}\mathbf J\mathbf g +\frac{h^3}{16}\mathcal H(\mathbf g,\mathbf g)+O(h^4). $$
For example, symmetry, $\mathcal H(\mathbf u,\mathbf v)=\mathcal H(\mathbf v,\mathbf u)$, gives the following second-degree term.
$$ \begin{aligned} \frac12\mathcal H(\mathbf d_3,\mathbf d_3) &=\frac12\left\{\frac{h^2}{4}\mathcal H(\mathbf g,\mathbf g) +2\frac h2\frac{h^2}{4}\mathcal H(\mathbf g,\mathbf J\mathbf g)\right\}+O(h^4)\\ &=\frac{h^2}{8}\mathcal H(\mathbf g,\mathbf g) +\frac{h^3}{8}\mathcal H(\mathbf g,\mathbf J\mathbf g)+O(h^4). \end{aligned} $$
Including the linear and cubic terms gives
$$ \begin{aligned} \mathbf k_3={}&\mathbf g+\frac h2\mathbf J\mathbf g +h^2\left\{\frac14\mathbf J^2\mathbf g+\frac18\mathcal H(\mathbf g,\mathbf g)\right\}\\ &+h^3\left\{\frac1{16}\mathbf J\mathcal H(\mathbf g,\mathbf g) +\frac18\mathcal H(\mathbf g,\mathbf J\mathbf g) +\frac1{48}\mathcal T(\mathbf g,\mathbf g,\mathbf g)\right\}+O(h^4). \end{aligned} $$
For the fourth stage,
$$ \mathbf d_4=h\mathbf k_3=h\mathbf g+\frac{h^2}{2}\mathbf J\mathbf g +h^3\left\{\frac14\mathbf J^2\mathbf g+\frac18\mathcal H(\mathbf g,\mathbf g)\right\}+O(h^4). $$
Compute the three substitution terms separately.
$$ \begin{aligned} \mathbf J\mathbf d_4&=h\mathbf J\mathbf g+\frac{h^2}{2}\mathbf J^2\mathbf g +h^3\left\{\frac14\mathbf J^3\mathbf g+\frac18\mathbf J\mathcal H(\mathbf g,\mathbf g)\right\}+O(h^4),\\ \frac12\mathcal H(\mathbf d_4,\mathbf d_4)&=\frac{h^2}{2}\mathcal H(\mathbf g,\mathbf g) +\frac{h^3}{2}\mathcal H(\mathbf g,\mathbf J\mathbf g)+O(h^4),\\ \frac16\mathcal T(\mathbf d_4,\mathbf d_4,\mathbf d_4)&=\frac{h^3}{6}\mathcal T(\mathbf g,\mathbf g,\mathbf g)+O(h^4). \end{aligned} $$
Adding these terms and $\mathbf g$ gives
$$ \begin{aligned} \mathbf k_4={}&\mathbf g+h\mathbf J\mathbf g +h^2\left\{\frac12\mathbf J^2\mathbf g+\frac12\mathcal H(\mathbf g,\mathbf g)\right\}\\ &+h^3\left\{\frac14\mathbf J^3\mathbf g+\frac18\mathbf J\mathcal H(\mathbf g,\mathbf g) +\frac12\mathcal H(\mathbf g,\mathbf J\mathbf g) +\frac16\mathcal T(\mathbf g,\mathbf g,\mathbf g)\right\}+O(h^4). \end{aligned} $$
Combine this with $\mathbf k_1=\mathbf g$ and apply the RK4 weights. The coefficients in the update are as follows.
$$ \begin{array}{c|c|c} \text{Term}&\text{RK4 coefficient}&\text{Exact coefficient}\\ \hline h\mathbf g&(1+2+2+1)/6=1&1\\ h^2\mathbf J\mathbf g&(2/2+2/2+1)/6=1/2&1/2\\ h^3\mathcal H(\mathbf g,\mathbf g)&(2/8+2/8+1/2)/6=1/6&1/6\\ h^3\mathbf J^2\mathbf g&(2/4+1/2)/6=1/6&1/6\\ h^4\mathcal T(\mathbf g,\mathbf g,\mathbf g)&(2/48+2/48+1/6)/6=1/24&1/24\\ h^4\mathcal H(\mathbf g,\mathbf J\mathbf g)&(2/8+1/2)/6=1/8&3/24\\ h^4\mathbf J\mathcal H(\mathbf g,\mathbf g)&(2/16+1/8)/6=1/24&1/24\\ h^4\mathbf J^3\mathbf g&(1/4)/6=1/24&1/24 \end{array} $$
Every term agrees. Let $\Phi_h$ be the RK4 one-step map. Starting from the exact value, the difference has the following order.
display(Latex(
r"\(\displaystyle \boxed{\mathbf y(t+h)-\Phi_h(t,\mathbf y(t))=O(h^5)}\)"
))
$$ \displaystyle \boxed{\mathbf y(t+h)-\Phi_h(t,\mathbf y(t))=O(h^5)} $$
4. Why the global error is fourth order
Here, “local error” means the one-step difference before division by $h$. Some references call the difference divided by $h$ the local truncation error, so it is important to check the definition.
Set $\mathbf e_n=\mathbf y(t_n)-\mathbf y_n$. Bound the local error norm by $Ch^5$, and assume that, for sufficiently small $h$, the Lipschitz constant of $\Phi_h$ is at most $1+Lh$. The constant $L\gt 0$ is independent of $h$.
$$ \begin{aligned} \mathbf e_{n+1}&=\mathbf y(t_{n+1})-\Phi_h(t_n,\mathbf y(t_n))\\ &\quad+\Phi_h(t_n,\mathbf y(t_n))-\Phi_h(t_n,\mathbf y_n),\\ \|\mathbf e_{n+1}\|&\le Ch^5+(1+Lh)\|\mathbf e_n\|. \end{aligned} $$
With exact initial data, $\mathbf e_0=\mathbf0$. Repeatedly applying the recurrence with fixed $Nh=T$ gives
$$ \begin{aligned} \|\mathbf e_N\|&\le Ch^5\sum_{j=0}^{N-1}(1+Lh)^j\\ &=Ch^5\frac{(1+Lh)^N-1}{Lh}\\ &\le\frac C L(e^{LT}-1)h^4=O(h^4). \end{aligned} $$
This is the meaning of fourth-order accuracy. Where $E(h)\approx Kh^4$, we have $E(h/2)/E(h)\approx1/16$. Measuring this ratio checks fourth-order convergence in an actual calculation.
5. Checking a linear equation numerically
For $y^{\prime}=y,\ y(0)=1$, the exact solution is $e^t$. Substituting the stages gives
$$ \begin{aligned} k_1&=y_n,\quad k_2=(1+h/2)y_n,\\ k_3&=(1+h/2+h^2/4)y_n,\\ k_4&=(1+h+h^2/2+h^3/4)y_n,\\ y_{n+1}&=R(h)y_n,\quad R(h)=1+h+\frac{h^2}{2}+\frac{h^3}{6}+\frac{h^4}{24}. \end{aligned} $$
This matches the exponential through fourth order. However, this linear example alone does not prove agreement of the nonlinear terms; the expansions above are needed for that.
z = sp.symbols("z")
R = sp.expand(rk4(lambda t, y: y, 0, sp.Integer(1), z))
assert R == sum(z**j / sp.factorial(j) for j in range(5))
# Display formulas as LaTeX instead of printing strings.
display(Latex(r"\(\displaystyle R(z)=" + sp.latex(R) + r"\)"))
display(Latex(r"\(\displaystyle e^z-R(z)="
+ sp.latex(sp.series(sp.exp(z) - R, z, 0, 7)) + r"\)"))
$$ \displaystyle R(z)=\frac{z^{4}}{24} + \frac{z^{3}}{6} + \frac{z^{2}}{2} + z + 1 $$
$$ \displaystyle e^z-R(z)=\frac{z^{5}}{120} + \frac{z^{6}}{720} + O\left(z^{7}\right) $$
f_linear = lambda t, y: y
methods = {"Euler": euler, "Midpoint": midpoint, "RK4": rk4}
fig, axes = plt.subplots(1, 2)
dense = np.linspace(0, 1, 200)
axes[0].plot(dense, np.exp(dense), "k-", label="Exact")
for name, step in methods.items():
t, y = solve(step, f_linear, 1, 1, 8)
axes[0].plot(t, y, "o--", label=name)
axes[1].semilogy(t[1:], abs(y[1:] - np.exp(t[1:])), "o-", label=name)
for ax in axes:
ax.set(xlabel="t")
ax.legend()
axes[0].set(ylabel="y", title="Solution, h = 0.125")
axes[1].set(ylabel="Absolute error", title="Error over time")
save_plot(fig, "02_linear_solution")
Let $E(h)$ be the error at $T=1$, and compute the observed order $p=\log_2(E(h)/E(h/2))$. Measure local error by taking one step from $y(0)=1$ for each step size. Dashed curves show $h^4$ and $h^5$ for comparison.
ns = 2 ** np.arange(2, 8)
hs = 1 / ns
errors = {}
fig, axes = plt.subplots(1, 2)
for name, step in methods.items():
errors[name] = np.array([
abs(solve(step, f_linear, 1, 1, int(n))[1][-1] - np.e) for n in ns
])
axes[0].loglog(hs, errors[name], "o-", label=name)
# Use h >= 1/64 for local error to avoid rounding effects in subtraction.
local_h = hs[:-1]
local = np.array([abs(np.exp(h) - rk4(f_linear, 0, 1, h)) for h in local_h])
axes[1].loglog(local_h, local, "o-", label="RK4 local error")
axes[0].loglog(hs, errors["RK4"][0] * (hs / hs[0])**4, "k--", label="$h^4$")
axes[1].loglog(local_h, local[0] * (local_h / local_h[0])**5, "k--", label="$h^5$")
for ax, title in zip(axes, ["Global error at T = 1", "One-step error"]):
ax.set(xlabel="h", ylabel="Absolute error", title=title)
ax.legend()
save_plot(fig, "03_convergence")
pprint([{"h": sig3(h), "RK4 error": sig3(error)}
for h, error in zip(hs, errors["RK4"])])
pprint({name: sig3(np.log2(err[-2] / err[-1])) for name, err in errors.items()})
pprint({"local order": sig3(np.log2(local[-2] / local[-1])),
"RK4 error ratio": sig3(errors["RK4"][-2] / errors["RK4"][-1])})
assert abs(np.log2(errors["RK4"][-2] / errors["RK4"][-1]) - 4) < 0.0500
[{'RK4 error': '7.19e-05', 'h': '0.250'},
{'RK4 error': '4.98e-06', 'h': '0.125'},
{'RK4 error': '3.28e-07', 'h': '0.0625'},
{'RK4 error': '2.10e-08', 'h': '0.0312'},
{'RK4 error': '1.33e-09', 'h': '0.0156'},
{'RK4 error': '8.38e-11', 'h': '7.81e-03'}]
{'Euler': '0.990', 'Midpoint': '1.99', 'RK4': '3.99'}
{'RK4 error ratio': '15.9', 'local order': '5.00'}
6. A nonlinear, time-dependent equation
Use $y^{\prime}=2ty^2,\ y(0)=1$. Separating variables gives
$$ \frac{dy}{y^2}=2t\,dt,\quad -\frac1y=t^2+C,\quad C=-1,\quad y(t)=\frac1{1-t^2}. $$
The solution diverges at $t=1$, so we compare only up to $T=0.500$. The right-hand plot checks that the error approaches fourth-order behavior in $h$.
f_nonlin = lambda t, y: 2 * t * y**2
end = 0.500
t, y = solve(rk4, f_nonlin, 1, end, 8)
hn = end / ns
en = np.array([abs(solve(rk4, f_nonlin, 1, end, int(n))[1][-1]
- 1 / (1 - end**2)) for n in ns])
fig, axes = plt.subplots(1, 2)
dense = np.linspace(0, end, 200)
axes[0].plot(dense, 1 / (1 - dense**2), label="Exact")
axes[0].plot(t, y, "o", label="RK4")
axes[0].set(xlabel="t", ylabel="y", title="Nonlinear, time-dependent ODE")
axes[1].loglog(hn, en, "o-", label="RK4")
axes[1].loglog(hn, en[0] * (hn / hn[0])**4, "k--", label="$h^4$")
axes[1].set(xlabel="h", ylabel="Endpoint error", title="Nonlinear convergence")
for ax in axes:
ax.legend()
save_plot(fig, "04_nonlinear")
pprint({"nonlinear order": sig3(np.log2(en[-2] / en[-1]))})
assert abs(np.log2(en[-2] / en[-1]) - 4) < 0.100
{'nonlinear order': '3.97'}
7. Checking a system of equations
For simple harmonic motion, set $\mathbf y=(q,p)^{\mathsf T}$ to obtain
$$ \mathbf y^{\prime}=\begin{pmatrix}0&1\\-1&0\end{pmatrix}\mathbf y,\qquad \mathbf y(0)=\begin{pmatrix}1\\0\end{pmatrix},\qquad \mathbf y(t)=\begin{pmatrix}\cos t\\-\sin t\end{pmatrix} $$
Measure the Euclidean norm of the two-component error at $T=2\pi$. The left plot shows the phase plane; the right shows error against step size.
A = np.array([[0, 1], [-1, 0]])
f_vector = lambda t, y: A @ y
end = 2 * np.pi
nv = 2 ** np.arange(4, 10)
hv = end / nv
exact_end = np.array([np.cos(end), -np.sin(end)])
ev = np.array([np.linalg.norm(solve(rk4, f_vector, [1, 0], end, int(n))[1][-1]
- exact_end) for n in nv])
t, y = solve(rk4, f_vector, [1, 0], end, 32)
fig, axes = plt.subplots(1, 2)
dense = np.linspace(0, end, 200)
axes[0].plot(np.cos(dense), -np.sin(dense), label="Exact")
axes[0].plot(y[:, 0], y[:, 1], "o", markersize=3, label="RK4")
axes[0].set(xlabel="q", ylabel="p", title="Phase plane", aspect="equal")
axes[1].loglog(hv, ev, "o-", label="RK4")
axes[1].loglog(hv, ev[0] * (hv / hv[0])**4, "k--", label="$h^4$")
axes[1].set(xlabel="h", ylabel="Endpoint error norm", title="System convergence")
for ax in axes:
ax.legend()
save_plot(fig, "05_system")
pprint({"system order": sig3(np.log2(ev[-2] / ev[-1]))})
assert abs(np.log2(ev[-2] / ev[-1]) - 4) < 0.0500
{'system order': '4.00'}
8. Check accuracy and stability separately
For $y^{\prime}=\lambda y$, the amplification factor is $R(h\lambda)$. With $\lambda=-1$, $h=2$ gives $R(-2)=1/3$, while $h=3$ gives $R(-3)=11/8\gt 1$. An overly large step can make the numerical solution grow even when the exact solution decays.
fig, ax = plt.subplots()
dense = np.linspace(0, 12, 300)
ax.semilogy(dense, np.exp(-dense), "k-", label="Exact")
for n in (6, 4):
t, y = solve(rk4, lambda t, y: -y, 1, 12, n)
ax.semilogy(t, abs(y), "o-", label=f"RK4, h = {12 // n}")
ax.set(xlabel="t", ylabel="Absolute value", title="Stability of RK4")
ax.legend()
save_plot(fig, "06_stability")
Conclusion
We showed why RK4 matches the exact Taylor expansion through fourth order and has error $O(h^4)$ over a fixed interval.
The stage locations and weights match the coefficients, including nonlinear terms. This gives one-step error $O(h^5)$ and, after accounting for error propagation, global error $O(h^4)$. The numerical experiments also showed that halving the step size reduced the endpoint error to about $1/16$.
The argument assumes a smooth solution over a fixed finite interval. Instability from large steps and rounding error from extremely small steps require separate consideration.