---
title: Euler, Improved Euler, and Runge–Kutta
module: Numerical Methods
moduleNumber: 7
lessonNumber: 1
order: 701
summary: >
  Most initial value problems have no closed-form solution, so the solution is
  approximated on a grid. Euler's method steps along the tangent line, the
  improved Euler method averages two slopes, and the classical Runge–Kutta
  method averages four. Each added stage raises the order of accuracy at the
  cost of more evaluations per step, measured by how the local and global
  truncation errors scale with the step size.
topics: [Numerical Methods]
sources:
  - book: Boyce
    ref: "Ch. 8 — Numerical Methods; §8.1 The Euler or Tangent Line Method; §8.2 Improvements on the Euler Method"
  - book: Boyce
    ref: "§8.3 The Runge–Kutta Method"
  - book: Simmons
    ref: "Ch. 14 §73 The Method of Euler; §75 An Improvement to Euler; §76 Higher-Order Methods"
draft: false
---

Analytic techniques (integrating factors, separation of variables, series,
Laplace transforms) solve a limited catalogue of equations. A generic
nonlinear first-order problem

$$
\frac{\d y}{\d t} = f(t, y), \qquad y(t_0) = y_0
$$

usually has no solution expressible in elementary functions, yet the existence
theorem still guarantees a unique solution $y = \phi(t)$ whenever $f$ and $f_y$
are continuous near $(t_0, y_0)$. A numerical method abandons the search for a
formula and instead produces a table of approximate values $y_1, y_2, \dots,
y_N$ at prescribed points $t_1, t_2, \dots, t_N$, each meant to approximate
$\phi(t_n)$.[^boyce-intro] We fix a uniform step size $h$, set $t_n = t_0 + nh$,
and abbreviate $f_n = f(t_n, y_n)$. Each method is a rule for advancing from
$y_n$ to $y_{n+1}$.

## Euler's method

The oldest and simplest rule comes from three equivalent readings of the same
approximation.

- **Tangent line.** At $(t_n, y_n)$ the differential equation gives the slope
  $f_n$. Follow that tangent for a horizontal distance $h$: the height changes
  by $h f_n$.
- **Difference quotient.** Replace $\phi'(t_n)$ by the forward difference
  $\bigl(\phi(t_{n+1}) - \phi(t_n)\bigr)/h$ in the equation and solve for
  $\phi(t_{n+1})$.
- **Truncated Taylor series.** Expand $\phi(t_n + h) = \phi(t_n) + \phi'(t_n) h +
  \tfrac{1}{2}\phi''(\bar t_n) h^2$ and drop the quadratic term.

All three yield the **Euler formula**.

> **Definition (Euler's method).** With uniform step size $h$ and $f_n = f(t_n,
> y_n)$, the Euler or tangent-line method advances by
>
> $$
> y_{n+1} = y_n + h f_n, \qquad n = 0, 1, 2, \dots
> $$
>
> Each step uses only the data at the current point $(t_n, y_n)$, so the method
> is a **one-step method**.

Geometrically the exact solution curve is replaced by a polygon of tangent
segments. For a convex solution ($\phi'' > 0$) every segment lies below the
curve, so the approximation drifts steadily downward; a concave solution drifts
the other way.

$$
% caption: Euler's method threads a chain of tangent segments through the slope
% field; for a convex solution each segment undershoots and the error $E_n =
% \phi(t_n) - y_n$ grows step by step.
\begin{tikzpicture}[scale=1.05, >=stealth, font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
% axes
\draw[->, black] (-0.2,0) -- (4.0,0) node[right, black!70] {$t$};
\draw[->, black] (0,-0.2) -- (0,3.3) node[above, black!70] {$y$};
% true solution (convex, increasing)
\draw[black!75, very thick, domain=0:3.35, samples=60] plot (\x, {0.5*exp(0.58*\x)});
\node[black!75] at (3.15,3.05) {true solution};
% euler polygon (below the curve)
\coordinate (p0) at (0,0.5);
\coordinate (p1) at (1,0.79);
\coordinate (p2) at (2,1.25);
\coordinate (p3) at (3,1.97);
\draw[acc, very thick] (p0) -- (p1) -- (p2) -- (p3);
\foreach \p in {(p0),(p1),(p2),(p3)} \fill[acc] \p circle (1.7pt);
\node[acc] at (2.55,1.35) {Euler};
% error bar at t3
\draw[dashed, black] (3,1.97) -- (3,2.84);
\node[black!70, anchor=west] at (3.05,2.42) {$E_3$};
% ticks
\foreach \t/\lab in {1/{$t_1$}, 2/{$t_2$}, 3/{$t_3$}} {
  \draw[black] (\t,0.06) -- (\t,-0.06);
  \node[black!70, anchor=north] at (\t,-0.08) {\lab};
}
\node[black!70, anchor=north] at (0,-0.08) {$t_0$};
\end{tikzpicture}
$$

Written as a program the method is a single loop; only line 4 encodes the
choice of rule, and the methods that follow replace that single line.

```algorithm
caption: $\textsc{Euler}(f, t_0, y_0, h, N)$ — tangent-line integration on $N$ steps
$t \gets t_0$, $y \gets y_0$
output $(t, y)$
for $n$ from $1$ to $N$ do
  $y \gets y + h \cdot f(t, y)$   // advance along the tangent
  $t \gets t + h$
  output $(t, y)$
end
```

### A test problem

The linear equation

$$
y' = 1 - t + 4y, \qquad y(0) = 1
$$

has the exact solution $\phi(t) = \tfrac{1}{4}t - \tfrac{3}{16} +
\tfrac{19}{16}e^{4t}$, which lets us monitor the error exactly. Its solutions
diverge quickly (the $e^{4t}$ term), so it is deliberately hard to track over a
long interval, and differences between methods show clearly.[^boyce-test]
Euler's method with several step sizes gives the following values, with the
percentage error against $\phi$ shown in parentheses.

| $t$ | $h = 0.05$ | $h = 0.01$ | $h = 0.001$ | Exact $\phi(t)$ |
| --- | --- | --- | --- | --- |
| $0.5$ | $7.2902$ | $8.3767\ (3.8\%)$ | $8.6771\ (0.40\%)$ | $8.7120$ |
| $1.0$ | $45.588$ | $60.037\ (7.5\%)$ | $64.383\ (0.79\%)$ | $64.898$ |
| $2.0$ | $1745.7$ | $3029.3\ (14\%)$ | $3484.2\ (1.6\%)$ | $3540.2$ |

Reaching $1.6\%$ accuracy at $t = 2$ requires $2000$ steps. The accuracy is
unimpressive because the error compounds: halving $h$ only halves the error,
and the error grows with $t$ as the solution steepens.

A single step is pure arithmetic. Taking the coarser $h = 0.1$, so the numbers
stay legible, and running five steps by hand:

> **Worked example.** Euler's method on $y' = 1 - t + 4y$, $y(0) = 1$ with
> $h = 0.1$. Each step evaluates $f_n = 1 - t_n + 4y_n$ and sets
> $y_{n+1} = y_n + 0.1\,f_n$.
>
> | $n$ | $t_n$ | $y_n$ | $f_n = 1 - t_n + 4y_n$ | $y_{n+1} = y_n + 0.1 f_n$ |
> | --- | --- | --- | --- | --- |
> | $0$ | $0.0$ | $1.0000$ | $5.0000$ | $1.5000$ |
> | $1$ | $0.1$ | $1.5000$ | $6.9000$ | $2.1900$ |
> | $2$ | $0.2$ | $2.1900$ | $9.5600$ | $3.1460$ |
> | $3$ | $0.3$ | $3.1460$ | $13.2840$ | $4.4744$ |
> | $4$ | $0.4$ | $4.4744$ | $18.4976$ | $6.3242$ |
>
> The tangent-line steps reach $y_5 = 6.3242$ at $t = 0.5$, against the exact
> $\phi(0.5) = 8.7120$: a $27\%$ error at this coarse step. Halving $h$ roughly
> halves that error, the signature of a first-order method.

## Truncation error and order

Two errors matter, and they must be kept separate.

> **Definition (Local truncation error).** The error introduced in a single
> step, assuming the input is exact. For step $n+1$, with $y_n = \phi(t_n)$
> assumed correct, $e_{n+1} = \phi(t_{n+1}) - y_{n+1}^{\ast}$, where
> $y_{n+1}^{\ast}$ is the value the formula produces from the exact $\phi(t_n)$.

> **Definition (Global truncation error).** The accumulated error at a point,
> $E_n = \phi(t_n) - y_n$, arising from applying an approximate formula to data
> that are themselves already approximate.

$$
% caption: Local error $e$ is the gap a single step opens from a point on the
% exact curve; global error $E$ is the larger accumulated gap of the full
% polygon, which also carries forward the error already made.
\begin{tikzpicture}[scale=1.25, >=stealth, font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[->, black] (-0.2,0) -- (3.9,0) node[right, black!70] {$t$};
\draw[->, black] (0,-0.15) -- (0,2.5) node[above, black!70] {$y$};
% exact curve
\draw[black!75, very thick, domain=0:3.5, samples=60] plot (\x, {0.5*exp(0.45*\x)});
\node[black!75, anchor=south] at (3.1,2.05) {exact};
% euler polygon (accumulated)
\draw[very thick] (0,0.5) -- (1,0.725) -- (2,1.05125) -- (3,1.5243);
\foreach \p in {(0,0.5),(1,0.725),(2,1.05125),(3,1.5243)} \fill \p circle (1.4pt);
\node[anchor=north] at (2.4,1.0) {Euler};
% exact points
\fill[black!75] (2,1.2298) circle (1.4pt);
\fill[black!75] (3,1.9287) circle (1.4pt);
% single tangent step from the exact point at t_n
\draw[thick, dashed] (2,1.2298) -- (3,1.7832);
\fill (3,1.7832) circle (1.4pt);
% local error gap at t_{n+1}
\draw[acc, thick] (3.03,1.7832) -- (3.03,1.9287);
\node[acc, anchor=west, font=\scriptsize] at (3.05,1.856) {$e$};
% global error gap at t_{n+1}
\draw[acc, thick] (2.88,1.5243) -- (2.88,1.9287);
\node[acc, anchor=east, font=\scriptsize] at (2.86,1.73) {$E$};
\foreach \t/\lab in {2/{$t_n$}, 3/{$t_{n+1}$}} {
  \draw[black] (\t,0.05) -- (\t,-0.05);
  \node[black!70, anchor=north] at (\t,-0.06) {\lab};
}
\end{tikzpicture}
$$

Subtracting the Euler step from the exact Taylor expansion isolates the local
error. Since the two share the terms $\phi(t_n) + h f_n$, only the quadratic
remainder remains:

$$
e_{n+1} = \phi(t_{n+1}) - y_{n+1}^{\ast} = \tfrac{1}{2}\phi''(\bar t_n)\, h^2,
\qquad t_n < \bar t_n < t_{n+1}.
$$

The local truncation error is proportional to $h^2$; a uniform bound is $|e_n|
\le \tfrac{1}{2} M h^2$ with $M = \max |\phi''|$ on the interval.[^boyce-lte] The
global error accumulates one local error per step over $\sim (T - t_0)/h$ steps,
which drops one power of $h$: it can be shown that $|E_n| \le K h$ on any finite
interval.[^boyce-gte] This scaling defines the method's order.

> **Definition (Order of a method).** A one-step method has **order** $p$ if its
> global truncation error on a finite interval is bounded by a constant times
> $h^p$, equivalently if its local truncation error is proportional to
> $h^{p+1}$. Euler's method is first order ($p = 1$).

For the test problem $\phi''(t) = 19 e^{4t}$, so the local error near $t = 2$ is
about $e^{8}/e^{0} \approx 2500$ times larger than near $t = 0$. A uniform step
sized for the hard end wastes effort at the easy end, which motivates
**adaptive** codes that shrink $h$ only where $\phi''$ is large.

## The backward Euler formula

Approximating the same integral by the value at the **right** endpoint gives the
**backward Euler formula**

$$
y_{n+1} = y_n + h f(t_{n+1}, y_{n+1}).
$$

The unknown $y_{n+1}$ now appears on both sides, so the formula is **implicit**:
each step requires solving an equation. For the linear test problem this is
routine algebra, but for nonlinear $f$ it needs an iterative solve. Backward
Euler is no more accurate than forward Euler (still order 1) and more expensive;
its advantage is stability, which matters for stiff problems, where an explicit
method forces an impractically small step.

> **Definition (Explicit vs. implicit method).** An **explicit** method gives
> $y_{n+1}$ by direct evaluation of known data. An **implicit** method defines
> $y_{n+1}$ through an equation containing $y_{n+1}$ itself, which must be solved
> at each step.

## The improved Euler method

Integrating the equation over one step turns the problem into approximating an
area:

$$
\phi(t_{n+1}) = \phi(t_n) + \int_{t_n}^{t_{n+1}} f\bigl(t, \phi(t)\bigr)\, \d t.
$$

Euler replaces the integrand by its left-endpoint value $f_n$: the area of a
rectangle. A better estimate averages the endpoint slopes, replacing the
rectangle by a trapezoid.

$$
% caption: Euler approximates the step integral by a left-endpoint rectangle
% (left); the improved Euler method uses a trapezoid averaging the two endpoint
% slopes (right), matching the curve far more closely.
\begin{tikzpicture}[scale=1.0, >=stealth, font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
% ---- left: rectangle ----
\begin{scope}
  \draw[->, black] (-0.1,0) -- (3.0,0) node[right, black!70] {$t$};
  \draw[->, black] (0,-0.1) -- (0,2.6);
  \fill[black!7] (0.5,0) rectangle (2.3,1.05);
  \draw[thick] (0.5,0) rectangle (2.3,1.05);
  \draw[black!75, very thick, domain=0.2:2.6, samples=40] plot (\x, {0.55+0.18*\x*\x});
  \fill[black!75] (0.5,1.05) circle (1.6pt);
  \draw[black] (0.5,0.05) -- (0.5,-0.05) node[anchor=north, black!70] {$t_n$};
  \draw[black] (2.3,0.05) -- (2.3,-0.05) node[anchor=north, black!70] {$t_{n+1}$};
  \node[black!70, anchor=south] at (1.15,1.1) {left rectangle};
\end{scope}
% ---- right: trapezoid ----
\begin{scope}[xshift=4.6cm]
  \draw[->, black] (-0.1,0) -- (3.0,0) node[right, black!70] {$t$};
  \draw[->, black] (0,-0.1) -- (0,2.6);
  \fill[acc!12] (0.5,0) -- (0.5,1.05) -- (2.3,2.0) -- (2.3,0) -- cycle;
  \draw[acc, thick] (0.5,0) -- (0.5,1.05) -- (2.3,2.0) -- (2.3,0);
  \draw[black!75, very thick, domain=0.2:2.6, samples=40] plot (\x, {0.55+0.18*\x*\x});
  \fill[black!75] (0.5,1.05) circle (1.6pt);
  \fill[black!75] (2.3,1.51) circle (1.6pt);
  \draw[black] (0.5,0.05) -- (0.5,-0.05) node[anchor=north, black!70] {$t_n$};
  \draw[black] (2.3,0.05) -- (2.3,-0.05) node[anchor=north, black!70] {$t_{n+1}$};
  \node[black!70, anchor=south] at (1.15,1.85) {trapezoid};
\end{scope}
\end{tikzpicture}
$$

The trapezoid rule uses $\tfrac{1}{2}\bigl(f(t_n, y_n) + f(t_{n+1},
y_{n+1})\bigr)$, but $y_{n+1}$ is unknown. Replacing it by the Euler prediction
removes the implicitness and gives an explicit two-stage rule.

> **Definition (Improved Euler / Heun's method).** Predict with an Euler step,
> then correct with the trapezoidal average:
>
> $$
> k_1 = f(t_n, y_n), \qquad k_2 = f(t_n + h, \; y_n + h k_1),
> $$
> $$
> y_{n+1} = y_n + \tfrac{h}{2}(k_1 + k_2).
> $$
>
> The local truncation error is proportional to $h^3$ and the global error to
> $h^2$, so the method is **second order**.

The cost is two evaluations of $f$ per step instead of one.[^boyce-heun] For a
fixed $h$ the improved Euler method does twice the work of Euler, or equivalently
matches Euler at half the step.

> **Worked example.** One improved Euler step on $y' = 1 - t + 4y$, $y(0) = 1$
> with $h = 0.1$. Predict a slope with Euler, then average the two endpoint
> slopes:
>
> $$
> k_1 = f(0, 1) = 1 - 0 + 4(1) = 5,
> $$
> $$
> k_2 = f(0.1,\; 1 + 0.1 \cdot 5) = f(0.1, 1.5) = 1 - 0.1 + 4(1.5) = 6.9,
> $$
> $$
> y_1 = 1 + \tfrac{0.1}{2}(5 + 6.9) = 1.595.
> $$
>
> The exact value is $\phi(0.1) = 1.6090$. A single Euler step gives $1.5$
> (error $0.109$); the trapezoidal average cuts the error to $0.014$, roughly an
> order of magnitude smaller for one extra evaluation of $f$.

On the test problem the improved Euler method with $h = 0.025$ ($160$
evaluations) is already slightly more accurate than Euler with $h = 0.001$
($2000$ evaluations): about one-twelfth the work for comparable accuracy.

## The Runge–Kutta method

Euler and improved Euler are the first two members of the **Runge–Kutta**
family, which sample $f$ at several points inside the step and take a weighted
average of the slopes. The classical fourth-order, four-stage method is the
standard general-purpose integrator.[^boyce-rk]

> **Definition (Classical Runge–Kutta, RK4).** Sample four slopes and combine
> them with weights $1, 2, 2, 1$:
>
> $$
> k_{n1} = f(t_n, y_n), \qquad
> k_{n2} = f\!\left(t_n + \tfrac{h}{2}, \; y_n + \tfrac{h}{2} k_{n1}\right),
> $$
> $$
> k_{n3} = f\!\left(t_n + \tfrac{h}{2}, \; y_n + \tfrac{h}{2} k_{n2}\right),
> \qquad
> k_{n4} = f(t_n + h, \; y_n + h k_{n3}),
> $$
> $$
> y_{n+1} = y_n + \frac{h}{6}\bigl(k_{n1} + 2 k_{n2} + 2 k_{n3} + k_{n4}\bigr).
> $$
>
> The local truncation error is proportional to $h^5$ and the global error to
> $h^4$: the method is **fourth order**.

Reading the four slopes: $k_{n1}$ is the slope at the left end; $k_{n2}$ is a
midpoint slope reached by an Euler half-step; $k_{n3}$ is a second, corrected
midpoint slope; $k_{n4}$ is the slope at the right end reached using $k_{n3}$.
The weighting counts the two midpoint slopes double.

$$
% caption: RK4 samples four slopes across one step — one at the left, two at the
% midpoint, one at the right — and advances by their $1{:}2{:}2{:}1$ weighted
% average.
\begin{tikzpicture}[scale=1.1, >=stealth, font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[->, black] (-0.1,0) -- (5.2,0) node[right, black!70] {$t$};
\draw[->, black] (0,-0.1) -- (0,3.0);
% true solution over one step
\draw[black!70, very thick, domain=0.2:4.6, samples=40] plot (\x, {0.7+0.09*\x*\x});
% endpoints of the step
\draw[black] (0.6,0.05) -- (0.6,-0.05) node[anchor=north, black!70] {$t_n$};
\draw[black] (2.6,0.05) -- (2.6,-0.05) node[anchor=north, black!70] {$t_n + h/2$};
\draw[black] (4.6,0.05) -- (4.6,-0.05) node[anchor=north, black!70] {$t_n + h$};
% slope segments
\draw[very thick] (0.05,0.66) -- (1.15,0.90);   \node at (0.55,1.18) {$k_1$};
\draw[very thick] (2.05,1.14) -- (3.15,1.62);   \node at (2.35,1.86) {$k_2$};
\draw[very thick] (2.05,1.02) -- (3.15,1.78);   \node at (3.35,1.35) {$k_3$};
\draw[very thick] (4.05,1.82) -- (5.05,2.64);   \node at (4.45,2.72) {$k_4$};
\foreach \x/\y in {0.6/0.732, 2.6/1.309, 4.6/2.605} \fill[black!70] (\x,\y) circle (1.7pt);
\end{tikzpicture}
$$

> **Worked example.** One RK4 step on $y' = 1 - t + 4y$, $y(0) = 1$ with
> $h = 0.2$. The four slopes, using $\tfrac{h}{2}k_{01} = 0.5$,
> $\tfrac{h}{2}k_{02} = 0.69$, and $h k_{03} = 1.532$ for the intermediate
> arguments, are
>
> $$
> k_{01} = f(0, 1) = 5, \qquad k_{02} = f(0.1,\; 1 + 0.5) = 6.9,
> $$
> $$
> k_{03} = f(0.1,\; 1 + 0.69) = 7.66, \qquad k_{04} = f(0.2,\; 1 + 1.532) = 10.928.
> $$
>
> Their weighted average advances the step:
>
> $$
> y_1 = 1 + \frac{0.2}{6}\bigl(5 + 2(6.9) + 2(7.66) + 10.928\bigr) = 1 + 1.5016 = 2.5016.
> $$
>
> The exact value is $\phi(0.2) = 2.5053$: four evaluations of $f$ in a single
> step of $h = 0.2$ land within $0.15\%$.

When $f$ depends on $t$ alone, the four slopes collapse to Simpson's rule for
$\int f\,\d t$, whose $h^5$ error is consistent with RK4's order. On the test
problem RK4 with $h = 0.2$ ($40$ evaluations) matches the accuracy of improved
Euler with $h = 0.025$ ($160$ evaluations) at a quarter of the work ($1.4\%$
versus $1.2\%$ error at $t = 2$); with $h = 0.05$ the value at $t = 2$ is correct
to four digits ($0.009\%$ error).

## Comparing the methods

Each added stage raises the order of accuracy and requires more evaluations of
$f$ per step. Since evaluating $f$ dominates the run time, the fair comparison
holds the total number of evaluations fixed.

| Method | Evaluations of $f$ per step | Local error $e_n$ | Global error $E_n$ | Order $p$ |
| --- | --- | --- | --- | --- |
| Euler | $1$ | $\propto h^2$ | $\propto h$ | $1$ |
| Backward Euler | $1$ (implicit) | $\propto h^2$ | $\propto h$ | $1$ |
| Improved Euler (Heun) | $2$ | $\propto h^3$ | $\propto h^2$ | $2$ |
| Runge–Kutta (RK4) | $4$ | $\propto h^5$ | $\propto h^4$ | $4$ |

The test problem, evaluated at $t = 2$ with roughly equal computational effort,
shows the ranking.

| Method | Step $h$ | Evaluations to $t = 2$ | Value at $t = 2$ | Error |
| --- | --- | --- | --- | --- |
| Euler | $0.001$ | $2000$ | $3484.2$ | $1.6\%$ |
| Improved Euler | $0.025$ | $160$ | $3496.7$ | $1.2\%$ |
| Runge–Kutta | $0.05$ | $160$ | $3539.9$ | $0.009\%$ |

At the same $160$ evaluations RK4 is more than a hundred times more accurate
than improved Euler. A higher-order method is more **efficient**: for the same
work it delivers better accuracy, and for the same accuracy it needs far less
work. On a log–log plot of error against step size, a method of order $p$
produces a straight line of slope $p$, so halving $h$ divides the error by
$2^p$.

$$
% caption: Global error versus step size on log–log axes. A method of order $p$
% traces a line of slope $p$, so RK4's error falls off far faster than Euler's
% as the step shrinks.
\begin{tikzpicture}[scale=1.0, >=stealth, font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[->, black] (-0.1,0) -- (5.0,0) node[right, black!70] {$\log h$};
\draw[->, black] (0,-0.1) -- (0,4.3) node[above, black!70] {$\log \|E\|$};
% order-1 (Euler): slope 1
\draw[black!70, very thick] (0.4,0.6) -- (4.4,3.9);
\node[black!70, anchor=west] at (4.0,3.55) {Euler ($p=1$)};
% order-2 (improved Euler): slope 2
\draw[very thick] (0.4,0.15) -- (4.4,3.5);
\node[anchor=west] at (2.55,1.55) {Heun ($p=2$)};
% order-4 (RK4): slope 4
\draw[acc, very thick, dashed] (0.4,-0.05) -- (2.9,3.5);
\node[acc, anchor=south] at (1.35,1.75) {RK4 ($p=4$)};
\node[black, anchor=north] at (0.5,-0.15) {smaller $h$};
\node[black, anchor=north] at (4.3,-0.15) {larger $h$};
\end{tikzpicture}
$$

## Step size, accuracy, and adaptive methods

A method's order fixes how fast error falls as $h \to 0$, but it does not fix
the right $h$ for a given tolerance. Since the local error is proportional to
$h^{p+1}$, the step needed for a target tolerance $\epsilon$ scales like
$\epsilon^{1/(p+1)}$, and the constant depends on derivatives of the unknown
solution. Practical codes estimate the local error as they run: compute the step
two ways (for instance with a $p$th- and a $(p{+}1)$th-order formula) and use the
difference as an error estimate. When the estimate exceeds the tolerance, shrink
$h$ and retry; when it is comfortably under, grow $h$ to save work.

Embedding a higher-order formula that **reuses** the same slope evaluations adds
almost no extra work. The Runge–Kutta–Fehlberg pair (RKF45) computes a fourth- and a
fifth-order estimate from one shared set of stages plus one extra, and its
1977 Fortran implementation RKF45 became a template for the adaptive integrators
in modern software.[^boyce-rkf]

[^boyce-intro]: **Boyce**, §8.1 — a numerical method approximates the solution of $y' = f(t,y)$, $y(t_0)=y_0$ on a mesh $t_n = t_0 + nh$ rather than seeking a closed form.
[^boyce-test]: **Boyce**, §8.1, Example 1 — the linear problem $y' = 1 - t + 4y$, $y(0)=1$ with exact solution $\phi(t) = \tfrac14 t - \tfrac{3}{16} + \tfrac{19}{16}e^{4t}$, used throughout Ch. 8 to compare methods.
[^boyce-lte]: **Boyce**, §8.1 — the Euler local truncation error $e_{n+1} = \tfrac12\phi''(\bar t_n)h^2$, bounded by $\tfrac12 M h^2$.
[^boyce-gte]: **Boyce**, §8.1, Problem 20 — the global truncation error bound $|E_n| \le K h$ for the Euler method on a finite interval, making it a first-order method.
[^boyce-heun]: **Boyce**, §8.2 — the improved Euler (Heun) formula as a two-stage predictor–corrector with local error proportional to $h^3$; also **Simmons**, §75.
[^boyce-rk]: **Boyce**, §8.3 — the classical fourth-order four-stage Runge–Kutta formula, its four-slope weighted average, and the Simpson's-rule reduction when $f = f(t)$; also **Simmons**, §76.
[^boyce-rkf]: **Boyce**, §8.3 — adaptive Runge–Kutta methods and the Runge–Kutta–Fehlberg (RKF45) embedded fourth/fifth-order pair.
