Week 04 · Numerical simulation and Euler stability

Recognize numerical oscillation in an otherwise smooth process.

← Week 3 · Subject contents · Week 5 →

Recognize numerical oscillation in an otherwise smooth process.

Work through the problem

For excess temperature y with y′ = −y, Euler updates yₙ₊₁ = yₙ + h(−yₙ) = (1−h)yₙ. The exact trajectory starting at 1 is e⁻ᵗ and is always positive. Euler can cross zero when h exceeds 1.

At h = 0.5 the multiplier is 0.5. At h = 1.5 it is −0.5, so the computed trajectory oscillates toward zero. At h = 2.5 its magnitude exceeds one and the approximate solution grows. Stability requires |1−h| < 1, while accuracy may require a much smaller step.

Euler updates can oscillate or diverge. Numerical excess temperature by number of steps. Series: h = 0.5, h = 1.5, h = 2.5.

Euler updates can oscillate or diverge.

Run the Python lab

import numpy as np
steps = np.arange(7)
curves = {}
for h in [.5, 1.5, 2.5]:
    y = (1-h)**steps
    print(h, y[:4], "end error", round(abs(y[-1]-np.exp(-h*steps[-1])), 4))
    curves[f"h = {h}"] = y
assert abs(curves["h = 2.5"][-1]) > 1

Output from the lab

0.5 [1.    0.5   0.25  0.125] end error 0.0342
1.5 [ 1.    -0.5    0.25  -0.125] end error 0.0155
2.5 [ 1.    -1.5    2.25  -3.375] end error 11.3906

Practice

  1. Does a positive multiplier guarantee accurate simulation?

Check your reasoning

  1. No. It prevents a sign flip here, but truncation error still depends on step size and horizon.

← Week 3 · Subject contents · Week 5 →

Further reading · MIT 6.262 · Discrete Stochastic Processes