Category: Differential Equations Level: 301
yn+1 = yn + h · f(xn, yn), here f(x, y) = y
Euler's method walks along a slope field in straight steps: read the slope, step forward h, repeat. Smaller steps track the true solution more closely.
Solve dy/dx = y starting from (0, 1). At the start the slope is the height, 1.
(x0, y0) = (0, 1), slope = 1
Move h = 0.5 to the right along that slope. The height rises by h times slope = 0.5, landing at (0.5, 1.5).
y1 = 1 + 0.5 · 1 = 1.5
At each new point, read the new slope and step again. The slopes 1.5, 2.25, and 3.375 grow with the height, so the path bends upward.
yn+1 = yn + 0.5 yn = 1.5 yn
The exact solution is y = eˣ, which reaches about 7.389 at x = 2. Euler falls short by about 2.33, because each step uses a slope that is already out of date.
e2 ≈ 7.389, Euler gives 5.0625
With h = 0.25 the path takes eight shorter steps and ends at about 5.96. The error drops from 2.33 to 1.43, and it keeps shrinking as h does.
h = 0.25: y(2) ≈ 1.258 ≈ 5.96
cd svg-generator python3 -m svgmath render eulers-method --out /tmp/eulers-method
Source: svgmath/diagrams/first_order_odes.py