Differential Equations › Section B · First order differential equations › Topic B.9

Euler's method and error

When an equation has no formula solution, you can still compute one step at a time along tangent lines. Euler's method is the simplest way to do it, and studying its errors teaches the questions every numerical method must answer: how accurate, how costly, and how stable.

Why approximate

Most differential equations met in science and engineering cannot be solved with a formula, and the methods of this section only reach special types. Numerical methods instead compute approximate values of the solution at a sequence of times. The Calculus topic "Slope fields and Euler's method" introduced Euler's method as walking along a slope field. This topic treats it as a numerical method in its own right: where the formula comes from, how large its errors are and how they shrink, how to judge accuracy without knowing the exact answer, and why a method can fail completely when the step is too large.

Where the formula comes from

For \(y' = f(t, y)\) with \(y(t_0) = y_0\), the tangent line at \((t_0, y_0)\) has slope \(f(t_0, y_0)\). Following it for a step of length \(h\) gives

y_{n+1} = y_n + h\,f(t_n, y_n), \quad t_{n+1} = t_n + h

Taylor's theorem, from the Calculus topic "Taylor polynomials and approximation", shows what this ignores:

y(t + h) = y(t) + h\,y'(t) + \frac{h^2}{2}y''(\xi)

for some \(\xi\) between \(t\) and \(t + h\). Euler's method keeps the first two terms and drops the last, so each step makes an error of about \(\frac{h^2}{2}y''\).

Worked example: four steps

Approximate \(y(1)\) for \(y' = 2t - y\), \(y(0) = 1\), with \(h = 0.25\). 1. \(y_1 = 1 + 0.25(0 - 1) = 0.75\). 2. The slope is now \(0.5 - 0.75 = -0.25\), so \(y_2 = 0.6875\). 3. The slope is \(1 - 0.6875 = 0.3125\), so \(y_3 = 0.765625\). 4. The slope is \(1.5 - 0.765625 = 0.734375\), so \(y_4 \approx 0.9492\). 5. Compare: the linear equation has exact solution \(y = 2t - 2 + 3e^{-t}\), so \(y(1) = 3e^{-1} \approx 1.1036\). The error is about 0.154, or 14% of the true value. The estimate is low because \(y'' = 3e^{-t} > 0\): the solution is concave up, so each tangent step falls below the curve.

Worked example: halving the step

Repeat the same problem with smaller steps and record the error at \(t = 1\). 1. \(h = 0.25\): estimate 0.9492, error 0.1544. 2. \(h = 0.125\): estimate 1.0308, error 0.0728. 3. \(h = 0.0625\): estimate 1.0682, error 0.0354. 4. Ratios: \(\frac{0.1544}{0.0728} \approx 2.1\) and \(\frac{0.0728}{0.0354} \approx 2.1\). Each halving of \(h\) roughly halves the error. This is the signature of a first-order method: the error at a fixed time is roughly proportional to \(h\). The price is clear too: each halving doubles the number of steps, so ten times the accuracy costs ten times the work.

Local and global error

Two kinds of error are worth separating. The local truncation error is the error made in one step, starting from exact data; for Euler it is about \(\frac{h^2}{2}y''\), proportional to \(h^2\). The global error is the total error at a fixed time \(T\), after \(\frac{T - t_0}{h}\) steps. Roughly, that many local errors of size \(h^2\) accumulate into a global error of size \(h\), and each error also carries forward into later steps. Errors can therefore grow as \(t\) increases, which is why an approximation that is good early on may drift later. A method whose global error is proportional to \(h^p\) is said to have order \(p\); Euler's method has order 1.

Judging accuracy without the answer

In real problems there is no exact solution to compare with. The standard check is to run the method twice, with steps \(h\) and \(\frac{h}{2}\). For a first-order method, the error of the finer run is roughly the difference between the two answers. In the example, \(1.0308 - 0.9492 = 0.0816\), a fair estimate of the true error, 0.0728, of the finer run. If the two runs agree to the number of digits you need, accept the finer one; if not, keep halving. Percent error, \(100 \times \frac{|\text{exact} - \text{approx}|}{|\text{exact}|}\), is the usual way to report error when the exact value is known.

Worked example: when Euler blows up

Apply Euler's method to \(y' = -20y\), \(y(0) = 1\), whose exact solution \(e^{-20t}\) decays rapidly. 1. Each step adds \(h(-20y_n)\), so \(y_{n+1} = (1 - 20h)y_n\) and \(y_n = (1 - 20h)^n\). 2. With \(h = 0.15\), the factor is \(-2\): the values are \(1, -2, 4, -8, 16\), oscillating and exploding. 3. The approximations decay only if \(|1 - 20h| < 1\), that is \(0 < h < 0.1\). 4. So for this equation a step must be below 0.1 for stability, whatever accuracy you need. This is numerical instability: a property of the method at that step size, not of the equation.

Backward Euler

The implicit, or backward, Euler method uses the slope at the end of the step instead of the start:

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

The unknown \(y_{n+1}\) appears on both sides, so each step requires solving an equation, by algebra or by Newton's method. The reward is stability. For \(y' = -20y\), the step becomes \(y_{n+1} = \frac{y_n}{1 + 20h}\), which decays for every \(h > 0\); with \(h = 0.15\) each step multiplies by 0.25. Equations mixing very fast and very slow decay, called stiff equations, are routinely solved with implicit methods for this reason. Backward Euler is still only first order.

Rounding error

Truncation error is not the only kind. Computers store numbers to about 16 significant digits in standard double precision, so every arithmetic operation introduces a tiny rounding error. With a reasonable step size these are negligible next to the truncation error. But shrinking \(h\) without limit means an enormous number of steps, and rounding errors then accumulate while each step's truncation error becomes tiny. Below some step size the total error stops improving and can even get worse. In practice, rather than taking absurdly small Euler steps, one switches to a higher-order method, the subject of "Runge-Kutta and multistep methods".

Common mistakes to avoid

First, evaluating the slope at the new point in ordinary Euler, or forgetting to update \(t\) along with \(y\). Second, using the original \(y_0\) in every step instead of the latest \(y_n\). Third, expecting halving \(h\) to quarter the error; for Euler it only halves it. Fourth, trusting a single run without a step-halving check. Fifth, blaming the equation when the numbers explode; check the stability condition, such as \(h < 0.1\) for \(y' = -20y\). Sixth, assuming smaller is always better, when rounding error eventually takes over.

Key takeaways

Euler's method, \(y_{n+1} = y_n + h\,f(t_n, y_n)\), follows tangent lines and drops the \(\frac{h^2}{2}y''\) Taylor term each step. Its local error is proportional to \(h^2\) and its global error to \(h\), so it is first order: halving \(h\) roughly halves the error and doubles the work. It underestimates concave-up solutions. Check accuracy by comparing runs at \(h\) and \(\frac{h}{2}\). On decaying problems like \(y' = -20y\), explicit Euler needs \(|1 - 20h| < 1\) to stay stable, while backward Euler is stable for every step. Rounding error limits how small steps can usefully be.

Flashcards

Flashcard

Euler's method

yₙ₊₁ = yₙ + h f(tₙ, yₙ), tₙ₊₁ = tₙ + h

Step along the tangent line.

Test your understanding

Question 1 of 5

Use Euler's method with h = 0.1 on y′ = t + y², y(0) = 1. What is the estimate of y(0.2)?

Question 2 of 5

Euler's method with h = 0.1 gives an error of 0.08 at t = 2. What error do you expect with h = 0.05?

Question 3 of 5

For which step sizes do Euler's approximations to y′ = −40y, y(0) = 1, decay rather than blow up?

Question 4 of 5

When does Euler's method tend to underestimate the solution over a step?

Question 5 of 5

Which formula is the backward (implicit) Euler method?

← Previous topicNext topic →