Euler’s Method for ODE’s
Source inspiration: (Mathew 2000-2019).
Description
Euler’s method is the simplest one-step numerical solver for an initial value problem \(y' = f(t,y)\), \(y(t_0)=y_0\), on \([t_0, b]\). It computes \(y_n \approx y(t_n)\) at the grid points \(t_n = t_0 + nh\) of \(m\) subintervals of width \(h = (b - t_0)/m\), and advances the solution by following the local tangent at each grid point:
\[ y_{n+1} = y_n + h\,f(t_n,y_n), \qquad t_{n+1}=t_n+h. \]
Mathews’ modified Euler method is the explicit midpoint method: it takes a half Euler step to the middle of the step and uses the slope there,
\[ y_{n+1} = y_n + h\,f\Bigl(t_n+\tfrac{h}{2},\ y_n+\tfrac{h}{2}f(t_n,y_n)\Bigr). \]
Mathews’ theorem for Euler’s method assumes that \(f\) is continuous and satisfies a Lipschitz condition in \(y\), and his precision theorem that the solution is in \(C^2[t_0, b]\). Then, in general, the local truncation error is \(O(h^2)\) and the global error is \(O(h)\), so halving \(h\) roughly halves the error. For smooth enough \(f\), modified Euler’s global error is \(O(h^2)\): halving \(h\) divides it by about 4.
The animations use \(y' = 1 - t\sqrt[3]{y}\), \(y(0) = 1\) on \([0, 5]\), with \(y(5) = 0.0081199\). Here \(f\) is not Lipschitz near \(y = 0\), but the solution never falls below \(y(5)\). The table gives the largest grid-point error for the five finest \(m\) that Case 1 and Case 2 share, with the observed order \(p = \ln(E_{\text{prev}}/E)/\ln(m/m_{\text{prev}})\) against the row above. It is about 1 for Euler and 2.1 to 2.3 for modified Euler, falling to 2.04 from \(m = 300\) to \(600\).
| \(m\) | \(h\) | Euler: largest error | \(p\) | modified Euler: largest error | \(p\) |
|---|---|---|---|---|---|
| 80 | 0.0625 | \(4.25 \times 10^{-2}\) | — | \(6.27 \times 10^{-4}\) | — |
| 90 | 0.05556 | \(3.77 \times 10^{-2}\) | 1.02 | \(4.81 \times 10^{-4}\) | 2.26 |
| 100 | 0.05 | \(3.39 \times 10^{-2}\) | 1.02 | \(3.83 \times 10^{-4}\) | 2.16 |
| 120 | 0.04167 | \(2.82 \times 10^{-2}\) | 1.01 | \(2.56 \times 10^{-4}\) | 2.20 |
| 150 | 0.03333 | \(2.25 \times 10^{-2}\) | 1.01 | \(1.59 \times 10^{-4}\) | 2.14 |
The error at \(t = 5\) alone misleads (Case 1, Case 2): late in the run \(\partial f/\partial y\) is strongly negative and damps the error made earlier. At \(m = 150\), Euler’s error at \(t = 5\) is \(-1.7 \times 10^{-6}\) and modified Euler’s \(1.8 \times 10^{-6}\), although Euler’s largest error is about 140 times larger.
In general, on \(y' = \lambda y\), each step multiplies the error it inherits by \(1 + z\) (Euler) or \(1 + z + z^2/2\) (modified Euler), with \(z = h\lambda\); for real \(z < 0\) both have size at most 1 only for \(-2 \le z \le 0\). Here \(\partial f/\partial y = -t/(3y^{2/3})\) reaches \(-41.3\) at \(t = 5\), so for \(m \le 103\), \(h\,|\partial f/\partial y|\) along the solution exceeds 2 before \(t = 5\), the shaded region in the frames. On the coarsest grids, Euler’s runs for \(m = 10\) to \(40\) zig-zag and dip below zero although the solution stays positive (Case 1), and modified Euler’s runs zig-zag for \(m = 12\) to \(24\) and turn upward before \(t = 5\) for \(m = 28\) to \(60\) (Case 2).
Heun’s Method, which corrects an Euler predictor with the trapezoidal rule, is also of order 2; Big “O” Truncation Error explains the notation, the Taylor Series Method and the Runge-Kutta Method reach higher orders, the Runge-Kutta-Fehlberg Method adapts the step size, and Predictor-Corrector Methods such as Adams-Bashforth-Moulton use several previous points.
Animations
Each animation below repeats one of Mathews’ step-refinement sweeps for the IVP \(y' = 1 - t\sqrt[3]{y}\), \(y(0)=1\) on \(0 \le t \le 5\). Each frame is a complete run with \(m\) subintervals (\(h=5/m\)), for the values of \(m\) in Mathews’ animation, drawn over a gray reference solution (fixed-step RK4 with 50 000 steps) and labelled with the computed \(y(5)\), its error at \(t=5\) and the largest error at any grid point of the run. A light red band marks where \(h\,|\partial f/\partial y|\), evaluated along the reference solution rather than the plotted run, exceeds the method’s stability limit.
Legacy archive note: Mathews’ animations Euleraa.gif and MEuleraa.gif are in the archive and sweep \(m\) in the same way; every \(y(5)\) printed in them agrees with the runs here when rounded to seven decimals. The module’s Examples 11 (Euler) and 12 (modified Euler) each print runs with \(m=40\), \(100\) and \(150\); their final values agree with this page’s frames for those \(m\).
Case 1 - Forward Euler step-refinement sweep, \(y' = 1 - t\sqrt[3]{y}\), \(y(0)=1\), \(m = 10\) to \(150\) subintervals
Behavior: The frames use the 20 values of Mathews’ animation, \(m = 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150\). The reference solution rises from \(y(0)=1\) to about \(1.4498\) near \(t=0.88\), then decays toward the nullcline \(y=1/t^3\) (where \(y'=0\)) and reaches \(y(5)=0.0081199\). For \(m=10\) to \(40\) the computed values zig-zag in the tail and dip below zero, although the exact solution stays positive; they end at \(y(5)\approx1.777\) for \(m=10\), \(0.391\) for \(m=30\) and \(-0.0174\) for \(m=40\) (the first of the module’s Example 11 runs, \(m=40\), \(100\) and \(150\)). At \(m=45\) the last steps still alternate, but by less than \(0.009\), too little to see at this scale. From \(m=50\) on the runs decrease steadily after their peak, and the error at \(t=5\) is small: \(-4.2\times10^{-6}\) at \(m=60\) and \(-1.7\times10^{-6}\) at \(m=150\), where \(y(5)\approx0.0081182\). It does not measure the accuracy of the run: \(\partial f/\partial y\) is strongly negative late in the run, which damps the error made earlier, and from \(m=55\) on the error at \(t=5\) is more than \(10^4\) times smaller than the largest error at any grid point (“max |error|” in each frame). For \(m=45\) to \(150\) that largest error lies between \(t=1.64\) and \(1.73\), after the peak, where the run is above the reference. It falls at every refinement in the sweep and, from \(m=45\) on, about halves when \(m\) doubles, as expected of a first-order method: \(5.7\times10^{-2}\) at \(m=60\), \(2.8\times10^{-2}\) at \(m=120\) and \(2.2\times10^{-2}\) at \(m=150\). The cause of the coarse-grid behaviour is stability: \(\partial f/\partial y=-t/(3y^{2/3})\) reaches \(-41.3\) at \(t=5\), so for steps longer than about \(h=0.0485\) (\(m\le103\); here \(m=10\) to \(100\)), \(h\,|\partial f/\partial y|\) along the reference solution exceeds Euler’s stability limit \(2\) before \(t=5\) (the shaded region in those frames). There, while the error is small compared with the reference solution, each step multiplies the error it inherits by about \(1+h\,\partial f/\partial y<-1\) and adds its own local error, so the inherited part is amplified with alternating sign. For \(m=10\) to \(40\) the error grows to more than \(25\) times the reference solution at the same \(t\), so this linear picture no longer holds and individual steps can shrink the error: at \(m=25\) the step from \(t=4.2\) takes it from \(+0.429\) to \(-0.009\). At \(m=10\) the onset is at \(t\approx2.92\), and for \(m=10\) to \(45\) the error at \(t=5\) is larger than just before the onset. For \(m=50\) to \(100\) the onset comes later, from \(t\approx3.95\) (\(m=50\)) to \(t\approx4.95\) (\(m=100\)), and the amplified part stays too small to see: these runs decrease steadily, and their error at \(t=5\) is smaller than just before the onset. For \(m=110\) to \(150\), \(h\,|\partial f/\partial y|\) stays below \(2\) up to \(t=5\).

Case 2 - Modified Euler (midpoint) step-refinement sweep, same IVP, \(m = 12\) to \(150\) subintervals
Behavior: The frames use the 21 values of Mathews’ animation, \(m = 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 70, 80, 90, 100, 120, 150\), and the same reference solution as Case 1. For \(m=12\) to \(24\) the tail zig-zags; at \(m=24\) only the last three steps alternate (\(+0.069\), \(-0.076\), \(+0.489\)), ending at \(y(5)\approx0.613\). For \(m=28\) to \(60\) the curve turns upward before \(t=5\) instead of following the decay (at \(m=28\) with one small dip of \(0.0075\) in the second-to-last step), rising from its minimum by \(0.35\) at \(m=28\), \(0.057\) at \(m=40\) and \(0.015\) at \(m=60\) (barely visible at this scale) and ending at \(y(5)\approx0.384\), \(0.0761\) (the first of the module’s Example 12 runs, \(m=40\), \(100\) and \(150\)) and \(0.0259\). At \(m=70\) the upturn is only \(0.0008\), too small to see, and from \(m=80\) on the runs decrease steadily after their peak. From \(m=16\) the error at \(t=5\) falls at every refinement in the sweep, to \(2.5\times10^{-4}\) at \(m=80\) and \(1.8\times10^{-6}\) at \(m=150\), where \(y(5)\approx0.0081217\). For \(m=16\) to \(70\) it is also the largest error of the run, but from \(m=80\) on the same damping as in Case 1 makes it \(2.5\) to \(87\) times smaller than the largest error, which lies between \(t=3.19\) and \(3.22\): \(6.3\times10^{-4}\) at \(m=80\) and \(1.6\times10^{-4}\) at \(m=150\). From \(m=80\) to \(150\) that largest error falls by a factor of \(3.9\), close to the \((150/80)^2\approx3.5\) of a second-order method, while Euler’s falls by \(1.9\), close to \(150/80\approx1.9\). At \(m=150\) it is about 140 times smaller than Euler’s \(2.2\times10^{-2}\), although the two errors at \(t=5\) are about the same size. The method’s amplification factor \(1+z+z^2/2\), with \(z=h\,\partial f/\partial y\), has size at most 1 on the negative real axis exactly for \(-2\le z\le0\), so its stability limit is \(2\), the same as Euler’s: for \(m\le103\) (here \(m=12\) to \(100\)), \(h\,|\partial f/\partial y|\) along the reference solution exceeds \(2\) before \(t=5\) (the shaded region), from \(t\approx2.99\) at \(m=12\) to \(t\approx4.95\) at \(m=100\), and for each of these \(m\) the error at \(t=5\) is larger than just before the onset. For \(m=120\) and \(150\), \(h\,|\partial f/\partial y|\) stays below \(2\) up to \(t=5\).
