Euler's method and the step size
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 SeeLock in a step count for tenfold accuracy.
- 2 TryPredict for Heun's method and a decaying equation.
- 3 ProveBuild the error bound, line by line.
- 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 ideasOne 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.
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.
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.
Lock in a step count
- Choose the number of steps n with the slider, from 10 to 2,000. The step is h = 1/n, and the figure shows Euler's polyline for your n.
- Aim for the fewest steps whose error at t = 1 is at most a tenth of the 10-step error. Press Lock in my count.
- The page then runs Euler's method for every count and plots the errors. Reach three goals with the slider.
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}|\).
How the page computes
For each \(n\) the page sets \(h = 1/n\), \(t_j = j/n\) and \(y_0 = 1\), and repeats \(y_{j+1} = y_j + h\,y_j(1 - t_j)\) for \(j = 0, 1, \ldots, n - 1\) in double precision. The error is the distance from \(y_n\) to \(\sqrt{e}\). The rounding in these sums is far below the errors shown (stage 3, What else follows, puts a number on it).
Three goals
Another method, another equation
The explorer, its goals and one more question open after you answer the prediction.
Explorer: Euler and Heun
Both curves are drawn; the buttons choose the method for the readout and the goals.
Goals
A decaying equation
The global error bound
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.
Problems
Each problem has hints and a full solution. Exact answers can be typed as a decimal or a fraction.
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
- R. L. Burden and J. D. Faires, Numerical Analysis, chapter 5, “Initial-Value Problems for Ordinary Differential Equations.”
- E. Hairer, S. P. Nørsett and G. Wanner, Solving Ordinary Differential Equations I: Nonstiff Problems, 2nd ed. (Springer, 1993), chapter II, on Runge–Kutta methods and their order.
- R. J. LeVeque, Finite Difference Methods for Ordinary and Partial Differential Equations (SIAM, 2007), chapters 5 to 7, on initial value problems, convergence and absolute stability.