# Runge-Kutta Method

The Runge-Kutta methods are iterative ways to calculate the solution of a differential equation. Starting from an initial condition, they calculate the solution forward step by step. The second-order formula (RK2) is:
\begin{equation} \begin{aligned} & k_1 = h f(x_n, y_n), \\ & k_2 = h f(x_n + \frac{h}{2}, y_n + \frac{k_1}{2}), \\ & y_{n+1} = y_n + k_2 + O(h^3). \\ \end{aligned} \end{equation} For the third-order formula, it holds:
\begin{equation} \begin{aligned} & k_1 = h f(x_n, y_n), \\ & k_2 = h f(x_n + \frac{h}{2}, y_n + \frac{k_1}{2}), \\ & k_3 = h f(x_n + h, y_n - k_1 + 2k_2), \\ & y_{n+1} = y_n + \frac{1}{6}(k_1 + 4k_2 + k_3) + O(h^4); \\ \end{aligned} \end{equation} and the forth-order formula (RK4) is:
\begin{equation} \begin{aligned} & k_1 = h f(x_n, y_n), \\ & k_2 = h f(x_n + \frac{h}{2}, y_n + \frac{k_1}{2}), \\ & k_3 = h f(x_n + \frac{h}{2}, y_n + \frac{k_2}{2}), \\ & k_4 = h f(x_n + h, y_n + k_3), \\ & y_{n+1} = y_n + \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4) + O(h^5). \\ \end{aligned} \end{equation} This method is reasonably simple and robust and is a good general candidate for numerical solution of differential equations. It should be noted that the methods explained here are all explicit.

The relevant Matlab codes can be downloaded using the following link:
Matlab Codes Bank