Unit 10, lesson 56

Euler's Method and Numerical Error

How Euler's method follows tangent steps of a chosen step size, how its local truncation error differs from its global error, what first order of accuracy means, and how step refinement and stability checks judge the numbers.

  • Video 56
  • Euler and Runge-Kutta Methods

Many differential equations have no solution formula, yet the equation still gives the slope of the solution at every point. You can stand at the initial point, walk a short time along the tangent, read the new slope and walk again, but how far from the true solution are you after many such steps? Throughout, tt is the independent variable, y′=dy/dty' = dy/dt, and the problem is y′=f(t,y)y' = f(t, y) with y(t0)=y0y(t_0) = y_0. This lesson builds Euler’s method, separates the error of a single step from the error left after many steps, and shows how halving the step and checking stability tell you whether the computed numbers deserve trust.

Key terms

Euler’s method

Definition Choose a step size h>0h > 0 and the grid times tn=t0+nht_n = t_0 + nh for n=0,1,2,…n = 0, 1, 2, \ldots. Euler’s method starts from the given value y0y_0 and computes

yn+1=yn+h f(tn,yn),y_{n+1} = y_n + h\,f(t_n, y_n),

so that yny_n approximates the exact value y(tn)y(t_n). To reach a final time T>t0T > t_0 in NN equal steps, take h=(T−t0)/Nh = (T - t_0)/N. The method is explicit, because the new value uses only numbers that are already known. It comes from the tangent line approximation y(tn+h)≈y(tn)+h y′(tn)y(t_n + h) \approx y(t_n) + h\,y'(t_n), where the equation supplies y′(tn)=f(tn,y(tn))y'(t_n) = f(t_n, y(t_n)). The broken line through the computed points is in general not a solution of the equation, and the numbers can approximate the solution only on an interval [t0,T][t_0, T] inside its interval of existence.

In plain words Read the slope where you are, follow that tangent for a time hh, then read the slope again where you land. The step size is the time between grid points. A smaller step follows the curve more closely but needs more steps to reach the same final time.

Example Take y′=−2yy' = -2y with y(0)=1y(0) = 1 and h=14h = \tfrac14. The slope at the start is −2-2. The slope at the new point (14,12)(\tfrac14, \tfrac12) is recomputed as −2⋅12=−1-2 \cdot \tfrac12 = -1, not reused, so the two steps are

y1=1+14(−2)=12,y2=12+14(−1)=14,\begin{gathered} y_1 = 1 + \tfrac14(-2) = \tfrac12, \\[0.4em] y_2 = \tfrac12 + \tfrac14(-1) = \tfrac14, \end{gathered}

at the times t1=14t_1 = \tfrac14 and t2=12t_2 = \tfrac12. The exact solution is y=e−2ty = e^{-2t}, since its derivative is −2e−2t-2e^{-2t} and its value at 00 is 11. At t=12t = \tfrac12 it equals e−1≈0.3679e^{-1} \approx 0.3679, while Euler’s method gives 0.250.25. On this equation every step multiplies the value by 1−2h1 - 2h, so yn=(1−2h)ny_n = (1 - 2h)^n, which here is (12)n(\tfrac12)^n.

Local truncation error

Definition Let yy be the exact solution. The local truncation error of Euler’s method at step n+1n + 1 is

τn+1=y(tn+1)−y(tn)−h f(tn,y(tn)),\begin{aligned} \tau_{n+1} &= y(t_{n+1}) - y(t_n) \\[0.4em] &\quad - h\,f\bigl(t_n, y(t_n)\bigr), \end{aligned}

the part of the exact change over the step that one Euler step, started from the exact value y(tn)y(t_n), misses. If yy has a continuous second derivative on [tn,tn+1][t_n, t_{n+1}], Taylor’s theorem with remainder gives a time ξn\xi_n in (tn,tn+1)(t_n, t_{n+1}) with

τn+1=h22 y′′(ξn),\tau_{n+1} = \frac{h^2}{2}\,y''(\xi_n),

so ∣τn+1∣≤Mh2/2\lvert \tau_{n+1} \rvert \le Mh^2/2 whenever ∣y′′∣≤M\lvert y'' \rvert \le M on the step. The local truncation error is therefore of order h2h^2. With this sign, a positive value means that the step lands below the exact solution. Some books divide by hh and call τn+1/h\tau_{n+1}/h the local truncation error, and with that convention it is of order hh, so a claim about local order should say which convention it uses.

In plain words Put the start of one step exactly on the true curve. The tangent ignores how the curve bends during the step, and the miss equals half of h2h^2 times the second derivative at some time inside the step, so it shrinks like h2h^2.

Example On y′=−2yy' = -2y an exact step multiplies the value by e−2he^{-2h}, and

e−2h=1−2h+2h2−43h3+⋯ .\begin{aligned} e^{-2h} &= 1 - 2h + 2h^2 \\[0.4em] &\quad - \tfrac43 h^3 + \cdots. \end{aligned}

Euler’s method keeps only 1−2h1 - 2h, so a step from the exact value y(tn)y(t_n) misses by τn+1=y(tn)(e−2h−1+2h)\tau_{n+1} = y(t_n)\bigl(e^{-2h} - 1 + 2h\bigr), whose leading term is 2h2 y(tn)2h^2\,y(t_n). The first step, from y(0)=1y(0) = 1 with h=14h = \tfrac14, has τ1=e−1/2−12≈0.1065\tau_1 = e^{-1/2} - \tfrac12 \approx 0.1065, close to 2h2=0.1252h^2 = 0.125. With h=18h = \tfrac18 the first miss is τ1≈0.0288\tau_1 \approx 0.0288, about 3.73.7 times smaller. The positive leading coefficient 22 explains why every tangent step lands low on this decaying curve.

Global error

Definition The global error at tnt_n is the computed value minus the exact value,

En=yn−y(tn),E_n = y_n - y(t_n),

after nn steps that start from y0=y(t0)y_0 = y(t_0). Subtracting the identity y(tn+1)=y(tn)+h f(tn,y(tn))+τn+1y(t_{n+1}) = y(t_n) + h\,f(t_n, y(t_n)) + \tau_{n+1} from the Euler step gives the exact recursion

En+1=En+h Dn−τn+1,Dn=f(tn,yn)−f(tn,y(tn)).\begin{aligned} E_{n+1} &= E_n + h\,D_n - \tau_{n+1}, \\[0.4em] D_n &= f(t_n, y_n) \\[0.4em] &\quad - f\bigl(t_n, y(t_n)\bigr). \end{aligned}

Now suppose that ff is continuous for t0≤t≤Tt_0 \le t \le T and all real yy, that it satisfies the Lipschitz condition ∣f(t,u)−f(t,v)∣≤L∣u−v∣\lvert f(t, u) - f(t, v) \rvert \le L \lvert u - v \rvert there with a constant L>0L > 0, and that the exact solution has a continuous second derivative on [t0,T][t_0, T] with ∣y′′∣≤M\lvert y'' \rvert \le M. Then, in exact arithmetic, every grid time tn≤Tt_n \le T satisfies

∣En∣≤Mh2L(eL(tn−t0)−1).\lvert E_n \rvert \le \frac{Mh}{2L}\left(e^{L(t_n - t_0)} - 1\right).

On a fixed finite interval the global error of Euler’s method is therefore of order hh.

In plain words The global error is the error you actually see at a given time. Each step adds a new local miss and carries the earlier error forward, and the Lipschitz condition limits how much one step can enlarge that earlier error, to at most the factor 1+hL1 + hL. Roughly (T−t0)/h(T - t_0)/h misses of size h2h^2 add up to an error of size hh.

Example On y′=−2yy' = -2y with h=14h = \tfrac14 we have Dn=−2EnD_n = -2E_n, so the recursion reads En+1=12En−τn+1E_{n+1} = \tfrac12 E_n - \tau_{n+1}. The first step gives E1=−τ1≈−0.1065E_1 = -\tau_1 \approx -0.1065. The second miss is τ2=e−1/2(e−1/2−12)≈0.0646\tau_2 = e^{-1/2}\bigl(e^{-1/2} - \tfrac12\bigr) \approx 0.0646, so E2≈−0.0533−0.0646≈−0.1179E_2 \approx -0.0533 - 0.0646 \approx -0.1179. The direct comparison y2−y(12)=14−e−1≈−0.1179y_2 - y(\tfrac12) = \tfrac14 - e^{-1} \approx -0.1179 agrees. The negative sign says that the computed value lies below the curve. For the bound, L=2L = 2 and ∣y′′∣=4e−2t≤4\lvert y'' \rvert = 4e^{-2t} \le 4 on [0,12][0, \tfrac12], so at t=12t = \tfrac12 the bound is 14(e−1)≈0.430\tfrac14(e - 1) \approx 0.430, well above the actual size 0.1180.118.

Order of accuracy

Definition A one-step method has order pp, a positive integer, if for every problem with a sufficiently smooth right side its local truncation error is of order hp+1h^{p+1} as h→0h \to 0. For Euler’s method and the Runge-Kutta methods of the next lessons, a Lipschitz condition on ff then makes the global error of order hph^p on a fixed interval [t0,T][t_0, T] inside the interval of existence. This means that there are constants CC and h0>0h_0 > 0 with ∣En∣≤Chp\lvert E_n \rvert \le Ch^p for every tn≤Tt_n \le T whenever 0<h≤h00 < h \le h_0. Euler’s method has order 11, with local truncation error of order h2h^2 and global error of order hh. Under the normalized convention that divides by hh, the local truncation error has the same order hph^p as the global error. The order describes the limit of small steps. For a coarse step the error ratios can be far from what the order predicts, and when the solution is less smooth than the analysis assumes, the observed order can be lower.

In plain words The order tells you how fast the error falls as the step shrinks. In a typical problem, once hh is small, halving it divides the global error by about 2p2^p. For Euler’s method, half the step gives about half the error for twice the work.

Example For y′=−2yy' = -2y with y(0)=1y(0) = 1, here are the Euler values and signed errors at the common time t=12t = \tfrac12. The last column divides the error in the row above by the error in its own row.

hhStepsEuler valueSigned errorRatio
1/41/4220.2500000.250000−0.117879-0.117879
1/81/8440.3164060.316406−0.051473-0.0514732.292.29
1/161/16880.3436090.343609−0.024271-0.0242712.122.12
1/321/3216160.3560740.356074−0.011805-0.0118052.062.06
1/641/6432320.3620550.362055−0.005824-0.0058242.032.03

The value for h=18h = \tfrac18 is exactly (34)4=81256(\tfrac34)^4 = \tfrac{81}{256}. The ratios approach 22, as order 11 predicts, while the coarsest pair is noticeably off.

Step refinement

Definition Step refinement repeats a computation with the step halved, and so with twice as many steps, and compares the results at the same final time TT. Write yhy_h for the value at TT computed with step hh. If the global error of a method of order pp behaves like ChpCh^p with CC independent of hh, then yh−yh/2≈(2p−1) C(h/2)py_h - y_{h/2} \approx (2^p - 1)\,C(h/2)^p, so the error of the finer result is estimated by

yh/2−y(T)≈yh−yh/22p−1.y_{h/2} - y(T) \approx \frac{y_h - y_{h/2}}{2^p - 1}.

Subtracting this estimate from yh/2y_{h/2} gives the improved value y(T)≈yh/2+(yh/2−yh)/(2p−1)y(T) \approx y_{h/2} + (y_{h/2} - y_h)/(2^p - 1), called Richardson extrapolation. Neither formula needs the exact solution, and both are estimates that become reliable only when hh is small enough for the leading term ChpCh^p to dominate. Results at different final times cannot be compared this way, because their difference also contains the change of the exact solution between those times.

In plain words Halve the step and see how far the answer moves. For Euler’s method the move is about as large as the error that remains in the finer answer, and repeated halving shows whether the answers settle down at the expected rate.

Example For y′=−2yy' = -2y at T=12T = \tfrac12, the steps h=18h = \tfrac18 and h=116h = \tfrac1{16} give 0.3164060.316406 and 0.3436090.343609. With p=1p = 1 the estimated error of the finer value is 0.316406−0.343609=−0.0272030.316406 - 0.343609 = -0.027203, and the actual error is −0.024271-0.024271. The extrapolated value 0.343609+0.027203=0.3708120.343609 + 0.027203 = 0.370812 is closer to e−1≈0.367879e^{-1} \approx 0.367879 than either computed value. The coarser pair h=14h = \tfrac14 and h=18h = \tfrac18 gives the estimate −0.066406-0.066406 for an actual error of −0.051473-0.051473, which shows that the estimate improves as hh shrinks.

Numerical stability and positivity

Definition Apply Euler’s method to the decay equation y′=−ayy' = -ay with a constant a>0a > 0 and y(0)=y0>0y(0) = y_0 > 0. The exact solution y0e−aty_0 e^{-at} stays positive and decreases to 00. Each Euler step multiplies by the same factor, so

yn=(1−ah)n y0.y_n = (1 - ah)^n\,y_0.

The computed values tend to 00 exactly when ∣1−ah∣<1\lvert 1 - ah \rvert < 1, which means 0<h<2/a0 < h < 2/a. They stay positive and decrease exactly when 0<1−ah<10 < 1 - ah < 1, which means 0<h<1/a0 < h < 1/a. At h=1/ah = 1/a the value drops to 00 after one step, for 1/a<h<2/a1/a < h < 2/a it alternates in sign while shrinking, at h=2/ah = 2/a it alternates with constant size, and for h>2/ah > 2/a its size grows without bound. Accuracy, numerical stability and positivity are three separate questions about the same computed numbers.

In plain words The exact solution always decays, but the Euler numbers decay only when the step is short compared with the time scale 1/a1/a. A step can keep the numbers bounded and still be inaccurate, and numbers that do decay can still turn negative in a model of a quantity that cannot be negative.

Example For y′=−2yy' = -2y the factor is 1−2h1 - 2h. Steps with 0<h<120 < h < \tfrac12 give positive decreasing values, and steps with 0<h<10 < h < 1 give decaying values. With h=34h = \tfrac34 the factor is −12-\tfrac12, and the values 11, −0.5-0.5, 0.250.25, −0.125-0.125 at t=0t = 0, 0.750.75, 1.51.5, 2.252.25 shrink while changing sign, although the true solution is positive. With h=1h = 1 they alternate between 11 and −1-1, and with h=54h = \tfrac54 the factor −32-\tfrac32 makes them grow. Even the safe step h=14h = \tfrac14 left an error of about −0.118-0.118 at t=12t = \tfrac12.

Check yourself

  1. Use Euler’s method with h=0.5h = 0.5 on y′=y−ty' = y - t, y(0)=2y(0) = 2, to approximate y(1)y(1). Check that y=1+t+ety = 1 + t + e^t is the exact solution, and give the signed error.
Show the answer

The first slope is f(0,2)=2f(0, 2) = 2, so y1=2+0.5⋅2=3y_1 = 2 + 0.5 \cdot 2 = 3 at t=0.5t = 0.5. The second slope is f(0.5,3)=2.5f(0.5, 3) = 2.5, so y2=3+0.5⋅2.5=4.25y_2 = 3 + 0.5 \cdot 2.5 = 4.25 at t=1t = 1. The proposed solution has y′=1+ety' = 1 + e^t, and also y−t=1+ety - t = 1 + e^t, with y(0)=1+0+1=2y(0) = 1 + 0 + 1 = 2. So y(1)=2+e≈4.7183y(1) = 2 + e \approx 4.7183, and the signed error is 4.25−4.7183≈−0.46834.25 - 4.7183 \approx -0.4683. The solution is concave up, because y′′=et>0y'' = e^t > 0, so each tangent step lands below the curve.

  1. Euler’s method with h=0.15h = 0.15 is applied to y′=−10yy' = -10y, y(0)=1y(0) = 1. Do the computed values decay, and are they positive? Which step sizes give values that are positive and decreasing?
Show the answer

The factor per step is 1−10⋅0.15=−0.51 - 10 \cdot 0.15 = -0.5, so the values are 11, −0.5-0.5, 0.250.25, −0.125-0.125 and so on. They decay in size, since the factor has absolute value below 11, but they alternate in sign, while the exact solution e−10te^{-10t} is positive. Decay requires ∣1−10h∣<1\lvert 1 - 10h \rvert < 1, which means 0<h<0.20 < h < 0.2. Positive decreasing values require 0<1−10h<10 < 1 - 10h < 1, which means 0<h<0.10 < h < 0.1. The step 0.150.15 meets the first condition and fails the second.

  1. Euler’s method on y′=−yy' = -y, y(0)=1y(0) = 1, gives 0.3486780.348678 at t=1t = 1 with h=0.1h = 0.1 and 0.3584860.358486 with h=0.05h = 0.05. Estimate the signed error of the finer value without using the exact solution, then compare with the truth. Why must both runs end at the same time?
Show the answer

Each step multiplies by 1−h1 - h, so the two values are 0.9100.9^{10} and 0.95200.95^{20}. With p=1p = 1 the denominator 2p−12^p - 1 equals 11, so the estimated error of the finer value is yh−yh/2=0.348678−0.358486=−0.009808y_h - y_{h/2} = 0.348678 - 0.358486 = -0.009808. The extrapolated value is 0.358486+0.009808=0.3682940.358486 + 0.009808 = 0.368294. The exact value is e−1≈0.367879e^{-1} \approx 0.367879, so the actual error of the finer value is about −0.009394-0.009394, close to the estimate. Both runs must end at t=1t = 1 because the estimate reads the change between them as approximation error. Values at different times would also differ because the exact solution itself changes between those times.

How this lesson connects

It also uses Taylor's theorem with remainder.