Ordinary Differential Equations

Euler's Method

↩ Back
Initial value problem
$$\frac{dy}{dx} = f(x,y), \qquad y(x_0) = y_0$$

Following the Tangent Line

When an ODE can't be solved exactly, we can still approximate the solution step by step.
At $(x_n,y_n)$ the slope of the solution curve is known exactly: it's $f(x_n,y_n)$. Euler's method moves forward a small step $h$ along that slope, treating the curve as if it were straight over that short distance.
x y x₀ y₀ x₁ y₁ x₂ y₂ x₃ y₃ x₄ y₄
exact solution Euler approximation (step $h$)

Iteration Steps

1
Choose a step size $h$, and set $x_0,y_0$ from the initial condition.
2
Evaluate the slope at the current point: $f(x_n,y_n)$.
3
Advance one step
$$x_{n+1} = x_n + h$$
4
Repeat until reaching the desired $x$.
$$y_{n+1} = y_n + h\,f(x_n,y_n)$$

Example

$y' = x+y, \quad y(0)=1, \quad h=0.1$
$n$ $x_n$ $y_n$ $f(x_n,y_n)=x_n+y_n$ $y_{n+1}=y_n+h f(x_n,y_n)$
00.01.0001.0001.100
10.11.1001.2001.220
20.21.2201.4201.362
30.31.3621.6621.528
Each row's $y_{n+1}$ becomes the $y_n$ of the next row. $x_n$ simply grows by $h$ every step.

Step Size and Error

1
Local error per step: order $h^2$.
2
Accumulated error over the full interval: order $h$: Euler's method is first-order.
3
Trade-off: smaller $h$ gives a more accurate approximation, but requires more steps (more computation).
More accurate alternatives (Improved Euler / Heun, Runge-Kutta) reduce this error without shrinking $h$ as much.