Lite / Engineering Complex Systems / 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?
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.
Predict
For dV/dt = −V/τ with τ = 2 s, you take Euler steps of h = 5 s. What happens?
- A slightly inaccurate decay
- The values flip sign and grow: the simulation explodes
- The answer is exact
Guess first, then reveal
Each Euler step multiplies V by (1 − h/τ) = 1 − 2.5 = −1.5. The magnitude grows by 1.5 each step and the sign flips. The physics decays; the numerics explode. Euler is stable for this equation only when h < 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/τ?
What the interactive shows (text version)
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/τ.
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
Intuitive
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.
Technical
Forward Euler: yₙ₊₁ = yₙ + h·f(tₙ, yₙ). Local truncation error O(h²), global O(h). Region of absolute stability for y′ = λy: |1 + hλ| < 1.
Mathematical
yₙ = y₀(1 − kh)^(t/h) → y₀e^(−kt) as h → 0, because (1 − kh)^(1/h) → e^(−k): the same limit that defines e.
Applied
Real simulators choose step sizes adaptively: they estimate the error each step (by comparing two methods) and shrink h where things change fast, grow it where they are calm.
Derivation: Euler's step factor, its error and its stability limit
For dy/dt = −k·y, one Euler step gives yₙ₊₁ = yₙ + h·(−k·yₙ) = (1 − kh)·yₙ.
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².
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.
After n steps yₙ = y₀(1 − kh)ⁿ. This decays only if |1 − kh| < 1, that is 0 < kh < 2, or h < 2τ.
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.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
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.
Reflect
Explain the difference between an inaccurate simulation and an unstable one, with an example of each.
Write your answer on paper or in your own notes. Lite never stores what you write.