Numerical Zoo · Differential equation

Euler's decay trap

The differential equation decays peacefully. A bad step size does not have to.

Why numerical analysts keep this one around

Consider y' = -15y with y(0) = 1. The exact solution is exp(-15x), so the physical solution simply decays toward zero. Nothing oscillates and nothing grows.

Euler's method updates y by multiplying by 1 - 15h at every step. That one factor tells us almost everything. If h is small enough, the numerical solution decays. If h is too large, the factor has magnitude greater than one and the numerical solution grows even though the differential equation is trying to kill it.

This is a beautiful teaching example because the instability belongs entirely to the discretization. We do not need a complicated equation to make numerical stability visible.

R setup

Start with the actual object.

f <- function(x, y) {
  -15 * y
}

# Stable-ish
euler(f, x0 = 0, y0 = 1, h = 0.05, n = 20)

# Unstable
euler(f, x0 = 0, y0 = 1, h = 0.2, n = 5)

By hand first

Do enough arithmetic to see the trap.

1

Euler gives y[n+1] = y[n] + h(-15y[n]) = (1 - 15h)y[n].

2

For h = 0.05, the multiplier is 0.25. Each step shrinks the magnitude.

3

For h = 0.2, the multiplier is -2. The sign alternates and the magnitude doubles. The ODE is stable; our numerical scheme is not.

What to look for

Now make it earn its reputation.

  • Run Euler, midpoint, and RK4 on the same equation.
  • Keep the total time interval similar while changing h.
  • The exact solution is easy to add in the Workbench, which makes visual smoothness a poor excuse for skipping an error calculation.
Keep this distinction:

The computer did not misunderstand the differential equation. It followed Euler's update perfectly. That is the problem.