Runge-Kutta method

Description

The Runge-Kutta methods are generalizations of the Euler formula, where the slope is substituted with a weighted average of the slopes in [xnxxn+1][x_n \le x \le x_{n+1}]:

yn+1=yn+h(w1k1+w2k2++wmkm)y_{n+1} = y_n + h(w_1k_1 + w_2k2 + \cdots + w_mk_m)

The weights (wiw_i) satisfy w1+w2++wm=1w_1 + w_2 + \cdots + w_m = 1 and k1=f(xn,yn)k_1 = f(x_n, y_n). The order of the method is mm, if m=1m = 1, we get the Euler formula.

Second order

yn+1=yn+h2(k1+k2)where:k1=f(xn,yn)k2=f(xn+h,yn+hk1)\begin{aligned} y_{n+1} & = y_n + \dfrac{h}{2}(k_1 + k_2) \\ & \text{where:} \\ k_1 & = f(x_n, y_n) \\ k_2 & = f(x_n + h, y_n + hk_1) \end{aligned}

Fourth order (RK4)

yn+1=yn+h6(k1+2k2+2k3+k4)where:k1=f(xn,yn)k2=f(xn+12h,yn+12hk1)k3=f(xn+12h,yn+12hk2)k4=f(xn+h,yn+hk3)\begin{aligned} y_{n + 1} & = y_n +\dfrac{h}{6}(k_1 + 2k_2 + 2k_3 + k_4) \\ & \text{where:} \\ k_1 & = f(x_n, y_n) \\ k_2 & = f(x_n + \frac{1}{2}h, y_n + \frac{1}{2}hk_1) \\ k_3 & = f(x_n + \frac{1}{2}h, y_n + \frac{1}{2}hk_2) \\ k_4 & = f(x_n + h, y_n + hk_3) \end{aligned}

Calculator