Skip to content
Tactiverge

School/□ Systems Engineer/Week 8

Euler's method and step-size error

Most differential equations have no formula solution. So computers cheat: take the slope now, step forward a little, repeat. When does that cheating go badly wrong?

About 40 min · 3 goals · Checked by automated tests

1.Why should I care?

Every physics engine, circuit simulator and robot simulator steps forward in time. Euler's method is the simplest stepper, and its two failure modes (slow convergence and outright instability) are the ones you must check for in any simulation you trust.

  • ◇ Carry out Euler steps yₙ₊₁ = yₙ + h·f(tₙ, yₙ) by hand.
  • ◇ Show that Euler's error is roughly proportional to h by halving the step.
  • ◇ Find the stability limit h < 2τ for dy/dt = −y/τ and recognise numerical instability.

2.Discover

Start with τ = 2 and h = 0.5: read the error table and its ratio. Now try h = 1, 2, 2.5 and watch the regime change from smooth, to overshooting, to oscillating forever, to unstable. Change τ: does the boundary move with h/τ?

Loading the interactive…

Can't use the interactive? Read a description instead

The Euler lab plots the exact exponential decay with Euler's points. With τ = 2 and h = 0.5 the points track the curve slightly low and the error halves when h halves. At h = 3 they zigzag about zero while shrinking; at h = 4 they oscillate with constant size; at h = 5 they zigzag and grow. The readout names the regime from h/τ.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1 · a fresh version every time

A falling object with linear drag obeys dv/dt = g − v/τ with g = 9.81 m/s², τ = 0.5 s and v(0) = 0. Take 5 Euler steps of h = 0.2 s. What is the Euler estimate of v, in m/s?

m/s

4.Predict

For dV/dt = −V/τ with τ = 2 s, you take Euler steps of h = 5 s. What happens?

Guess first. Being wrong here is how the surprise works.

5.Understand

The method

Know the state yₙ at time tₙ. Compute the slope f(tₙ, yₙ) from the equation. Step: yₙ₊₁ = yₙ + h·f(tₙ, yₙ), tₙ₊₁ = tₙ + h. Repeat. That is all, and it is exactly how the week 4 forward difference is used in reverse.

Accuracy: first order

Euler's global error ∝ h. To get ten times more accurate, take ten times more steps. Check any simulation by halving h: if the answer changes noticeably, the step was too large. Better methods (such as Runge–Kutta) reach error ∝ h⁴ for a little more work per step.

Stability: a separate danger

Accuracy and stability are different. Too large a step can make a decaying system grow without limit. For dy/dt = −y/τ the limit is h < 2τ, and smooth results need h < τ. Fast processes (small τ) therefore force small steps even when you only care about slow ones.

Explain it another way

Euler is driving with your eyes shut, opening them only every h seconds to check the road's direction. Short blinks keep you on the road; long ones put you in a ditch, or the other side of the road.

Derivation: Euler's step factor, its error and its stability limit
  1. For dy/dt = −k·y, one Euler step gives yₙ₊₁ = yₙ + h·(−k·yₙ) = (1 − kh)·yₙ.

  2. The exact solution multiplies by e^(−kh) = 1 − kh + (kh)²/2 − … each step. The difference per step is about (kh)²/2: the local error ∝ h².

  3. To reach a fixed time T takes T/h steps, so the errors add to about (T/h)·h² ∝ h: the global error is first order. Halve h, halve the error.

  4. After n steps yₙ = y₀(1 − kh)ⁿ. This decays only if |1 − kh| < 1, that is 0 < kh < 2, or h < 2τ.

  5. For 1 < kh < 2 the factor is negative: the numerical solution overshoots zero every step while shrinking. For kh > 2 it grows without bound: numerical instability, not physics.

Worked example 1

dV/dt = −V/2, V(0) = 5 V, h = 0.5 s. Take two Euler steps.

Factor 1 − 0.5/2 = 0.75. V₁ = 3.75 V, V₂ = 2.8125 V. Exact V(1) = 5e^(−0.5) = 3.033 V. Error 0.22 V; with h = 0.25 it would be about half.

Common mix-ups

  • If a simulation blows up, the physical system is unstable.
    ✓ It may be numerical instability from too large a step. Halve h and see if it persists.
  • A stable simulation is an accurate one.
    ✓ Stable only means it does not explode. Accuracy needs a convergence check.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

dV/dt = −V/τ with τ = 2 s and V(0) = 5 V. One Euler step of h = 0.5 s gives what V, in volts?

V

Practice 3

For dy/dt = −y/τ with τ = 2 s, what is the largest Euler step (in seconds) that does not blow up?

s

Practice 4

You halve Euler's step size (staying well inside the stable range). Roughly what happens to the error at a fixed time?

Practice 5 · a fresh version every time

A falling object with linear drag obeys dv/dt = g − v/τ with g = 9.81 m/s², τ = 1 s and v(0) = 0. Take 4 Euler steps of h = 0.1 s. What is the Euler estimate of v, in m/s?

m/s

7.Apply it

Code Euler's method for dT/dt = −(T − 20)/8, T(0) = 90, up to t = 20. Run h = 4, 2, 1, 0.5 and tabulate T(20) against the exact value. Confirm the error halves, and find the step at which the solution first overshoots 20 °C.

8.Reflect

Concepts: Simulation and time stepping · First-order differential equations · Stability, overshoot and delay