Euler's Method

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.

Step through it

Watch it

Animated walkthrough

Step by step

Step 1: Start with a point and a slope

Solve dy/dx = y starting from (0, 1). At the start the slope is the height, 1.

(x0, y0) = (0, 1), slope = 1

Step 1: Start with a point and a slope

Step 2: Take one step

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

Step 2: Take one step

Step 3: Repeat

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

Step 3: Repeat

Step 4: Compare with the true solution

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

Step 4: Compare with the true solution

Step 5: Halve the step

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

Step 5: Halve the step

All steps at once

Storyboard

Generate it yourself

cd svg-generator
python3 -m svgmath render eulers-method --out /tmp/eulers-method

Source: svgmath/diagrams/first_order_odes.py