Hexa Scholar

Euler's method and the step size

Two chains of wooden planks laid along a glowing gold curve on a navy hillside: four long planks drift above the curve while many tiny planks hug it.
Long straight planks drift off the curve; short ones stay close.

The question

For y′ = y(1 − t), y(0) = 1, Euler with 10 steps misses y(1) by ≈ 0.0531. How many steps cut that error tenfold?

Pick a step count and lock it in; then the page runs every count from 10 to 2,000.

  1. 1 SeeLock in a step count for tenfold accuracy.
  2. 2 TryPredict for Heun's method and a decaying equation.
  3. 3 ProveBuild the error bound, line by line.
  4. 4 ApplyProblems on step counts, interest and bounds.
Before you start · 3 quick checks on slopes, tangent lines and log-log plots, about 3 min

Two ideas before you start

2 ideas

One step follows the slope

Figure (needs JavaScript): the solution of y′ = y(1 − t) from (0, 1), the slope line at the start, and one Euler step of size 1 along it.

Show

Slope at (0, 1): f(0, 1) = 1 · (1 − 0) = 1

From a point (t₀, y₀), Euler's method moves along the slope f(t₀, y₀) that the equation gives there, for one step of length h. The card draws h = 1 so the step is easy to see.

Exact definition

Initial value problem. Given a function \(f(t, y)\), a start \(t_0\) and a value \(y_0\), find \(y\) with \(y'(t) = f(t, y(t))\) for \(t_0 \le t \le T\) and \(y(t_0) = y_0\).

Euler's method. Choose a whole number \(N \ge 1\), the step \(h = (T - t_0)/N\) and the times \(t_n = t_0 + nh\). Start from \(y_0\) and set

\[y_{n+1} = y_n + hf(t_n, y_n)\]

for \(n = 0, 1, \ldots, N - 1\). Each \(y_n\) estimates \(y(t_n)\).

Steps add up

Figure (needs JavaScript): the solution of y′ = y(1 − t) on 0 ≤ t ≤ 1 and Euler's polyline with h = 0.1 up to the chosen step, with the gap at its end.

After

1 step: y₁ = 1.1 y(0.1) ≈ 1.0997 gap ≈ 3.41 × 10⁻⁴

Each step starts from the computed value, not from the true one, so the gaps carry over from step to step. At t = 1 the 10-step gap is the error in the question.

Exact definition

Global error. The error of Euler's method at \(t_n\) is \(e_n = y(t_n) - y_n\), the gap between the true solution and the computed value. The error at the end, \(e_N\) at \(t_N = T\), is the one the question asks about, in size \(|e_N|\).

Local error. One step started from the true value \(y(t_n)\) misses \(y(t_{n+1})\) by

\[\begin{aligned} \tau_n &= y(t_{n+1}) - y(t_n) \\ &\quad - hf(t_n, y(t_n)). \end{aligned}\]
Fine print: names, scope and notation

This is the forward, or explicit, Euler method: the new value is computed directly from the old one. The page treats one equation \(y' = f(t, y)\) for one unknown function and steps of equal length. The slope \(f(t_n, y_n)\) at a point is the one a slope field draws there.

For \(y' = y(1 - t)\) and \(y(0) = 1\) the solution is \(y(t) = e^{t - t^2/2}\): its derivative is \((1 - t)e^{t - t^2/2}\), so \(y' = y(1 - t)\). At \(t = 1\) it equals \(\sqrt{e} \approx 1.6487\). With \(n\) steps on \([0, 1]\) the step is \(h = 1/n\). The page computes in double precision; rounding is far smaller than every error shown.

1 See

Lock in a step count

The equation is \(y' = y(1 - t)\) with \(y(0) = 1\), and the target value is \(y(1) = \sqrt{e}\). Euler's method with \(n\) steps returns a value \(y_n\) at \(t = 1\); its error is \(|y_n - \sqrt{e}|\).

2 Try

Another method, another equation

The explorer, its goals and one more question open after you answer the prediction.

3 Prove

The global error bound

Theorem

Assumptions. \(f(t, y)\) is defined and continuous for \(t_0 \le t \le T\) and every real \(y\), and there is a number \(L \gt 0\) with \(|f(t, y) - f(t, z)| \le L|y - z|\) for all such \(t\), \(y\) and \(z\) (a Lipschitz condition). The solution \(y\) of \(y' = f(t, y)\), \(y(t_0) = y_0\), is twice continuously differentiable on \([t_0, T]\); \(M \gt 0\) is the largest value of \(|y''|\) there, and \(y''(t) \ne 0\) for every \(t\) with \(t_0 \lt t \lt T\). Euler's method takes \(N \ge 1\) steps of \(h = (T - t_0)/N\) from \(y_0\), with \(t_n\) and \(y_n\) as in the first key idea. Write \(e_n = y(t_n) - y_n\) for the error and

\[\begin{aligned} \tau_n &= y(t_{n+1}) - y(t_n) \\ &\quad - hf(t_n, y(t_n)) \end{aligned}\]

for the local error of one step from the true value.

Conclusion. For \(n = 0, 1, \ldots, N\),

\[|e_n| \le \frac{Mh}{2L}\bigl(e^{L(t_n - t_0)} - 1\bigr).\]

At the end, \(|e_N| \le B(h)\) with \(B(h) = \tfrac{Mh}{2L}\bigl(e^{L(T - t_0)} - 1\bigr)\), a constant times \(h\).

Why \(y'' \ne 0\). The result does not need it; it makes every \(\tau_n\) nonzero, which keeps each wrong option below false in every allowed case. Without it the same steps prove the same bound.

On this page. The equation \(y' = y(1 - t)\) on \([0, 1]\) meets every assumption (scratch work, after the proof).

Facts the proof uses.

  • Taylor's theorem with the Lagrange remainder, from the lesson on Taylor polynomials: if \(y\) is twice continuously differentiable on \([a, a + h]\), there is a \(\xi\) in \((a, a + h)\) with \[\begin{aligned} y(a + h) &= y(a) + hy'(a) \\ &\quad + \tfrac{1}{2}h^2y''(\xi); \end{aligned}\]
  • the triangle inequality \(|a + b + c| \le |a| + |b| + |c|\);
  • \(1 + x \lt e^x\) for every \(x \gt 0\), and induction on \(n\).

Each option is one step about the fixed \(f\), \(h\) and \(n\). Pick the one that is true for every \(f\), \(h\) and \(n\) the theorem allows.

4 Apply

Problems

Each problem has hints and a full solution. Exact answers can be typed as a decimal or a fraction.

Key point Euler's method follows the slope for one step at a time. Its error at a fixed time is of order \(h\), so the number of steps grows in proportion to the accuracy you ask for. A method of order \(h^2\), such as Heun's, needs far fewer steps; and for a decaying equation the step must also be small enough that each step does not magnify the values.
Level Intro Prerequisites Slope fields and Taylor polynomials; tangent lines and log-log plots (refreshed in Before you start) Time ~35 min

Related: finite differences (Euler's step rearranges to \((y_{n+1} - y_n)/h = f(t_n, y_n)\), a forward difference set equal to the slope); bisection (its error bound halves with every step, while Euler's shrinks only like \(1/n\)).

Further reading