Department of Applied Mathematics and Theoretical Physics

Numerical Analysis Course

Numerical Methods for First Order ODEs

Here we consider numerical methods to solve differential equations of the form

$y'(x) = f(x,y)$

with a given intial condition $y_0 = y(x_0)$.

In particular, we will look at the Forward Euler, Backward Euler, Trapezoid, Runge-Kutta 4, Adam-Bashforth 2 and Heun methods.

Contents

Forward Euler

The formula is:

$y_{n+1} = y_n + hf(x_n,y_n)$

where $h$ is the step-size.

Backward Euler

The formula is:

$y_{n+1} = y_n + hf(x_{n+1},y_{n+1})$

where $h$ is the step-size.

Trapezoidal

The formula is:

$y_{n+1} = y_n + \frac{1}{2}h(f(x_n,y_n) + f(x_{n+1},y_{n+1}))$

where $h$ is the step-size.

Runge-Kutta 4

This is the following 4th-order Runge-Kutta method:

$y_{n+1} = y_n + \frac{1}{6} \left(k_1 + 2k_2 + 2k_3 + k_4 \right)$

with

$k_1 = hf(x_n, y_n)$,

$k_2 = hf(x_n + \frac{1}{2}h , y_n +  \frac{1}{2} k_1)$,

$k_3 = hf(x_n + \frac{1}{2}h , y_n +   \frac{1}{2} k_2)$,

$k_4 = hf(x_n + h , y_n + k_3)$.

where $h$ is the step-size.

Adam-Bashforth 2

This is a two-step method with the following formula:

$y_{n+2} = y_{n+1} + h\left( \frac{3}{2} f(x_{n+1}, y_{n+1}) - \frac{1}{2} f(x_n, y_n)\right)$

where $h$ is the step-size.

Heun

Heun's method has the following formula:

$\tilde{y}_{i+1} = y_i + h f(x_i,y_i)$

$y_{i+1} = y_i + \frac{h}{2}(f(x_i, y_i) + f(x_{i+1},\tilde{y}_{i+1}))$.

where $h$ is the step-size. So in Heun's method, there is a first approximation at the intermediate value, and then the final approximation at the next integration point.

The GUI

Running the downloadable MATLAB® code on this page opens a GUI which allows you to compare different numerical methods for first order ODEs.

IB_ODE_GUI
    @(x)(func(x))

The Code

All files as zip archive: ode_all.zip