The
Runge-Kutta method for integrating an
ODE dy/dx = f(x,y) is derived by assuming the general form
yn+1 = yn + ak1 + bk2 + ...
where
k1 = h f(xn, yn)
k2 = h f(xn+alpha*h, yn+beta*k1)
etc. and h is the step size
and substituting in
Taylor expansions to find coefficients (a, b, ..., alpha, beta, ...) that will cancel out error terms.
The most popular RK method is the 4th order Runge Kutta where
yn+1 = yn + (k1 + 2k2 + 2k3 + k4)/6
k1 = h f(xn, yn)
k2 = h f(xn+h/2, yn+k1/2)
k3 = h f(xn+h/2, yn+k2/2)
k4 = h f(xn+h, yn+k3)
The 4th order Runge-Kutta has
local truncation error of order O(h
5), giving total
error of order O(h
4). It is fairly
stable,
self-priming, and simple to implement, making it popular for quick-n-dirty applications. Generally Runge-Kutta is used with an
adaptive step size algorithm to control the error.