Runge-Kutta-Fehlberg 4/5th-order method

The Runge-Kutta-Fehlberg 4th-order method with 5th-order error checking (RKF45) is a numerical integration technique for ordinary differential equations (ODEs) that utilizes an adaptive step size to achieve a prescribed error tolerance, ϵ\epsilon. It is used by each page in this website that solves an ODE system. In it, we assume our ODE system has the form

dxdt=f(x,t).\begin{aligned} \dfrac{d\mathbf{x}}{dt} &= f(\mathbf{x}, t). \\ \end{aligned}

To numerically integrate this system, we discretize our domain of tt values. We will not know how many points we discretize our domain into until after we have finished the integration, due to our adaptive step size. At each step ii, we will use the step size hih_i and we will utilize the integration scheme

k1,i=hif(xi,ti)k2,i=hif(xi+k1,i4,ti+hi4)k3,i=hif(xi+3k1,i32+9k2,i32,ti+3hi8)k4,i=hif(xi+1932k1,i21977200k2,i2197+7296k3,i2197,ti+12hi13)k5,i=hif(xi+439k1,i2168k2,i+3680k3,i513845k4,i4104,ti+hi)k6,i=hif(xi8k1,i27+2k2,i3544k3,i2565+1859k4,i410411k4,i40,ti+hi2)X1,i=xi+25k1,i216+1408k3,i2565+2197k4,i4104k5,i5X2,i=xi+16k1,i135+6656k3,i12825+28561k4,i564309k5,i50+2k6,i55Ri=X1,iX2,ihiSi=[ϵ2Ri]1/4ri=maxRisi=minSihi=sihi.\begin{aligned} \mathbf{k}_{1,i} &= h_if(\mathbf{x}_i, t_i) \\ \mathbf{k}_{2,i} &= h_if\left(\mathbf{x}_i + \dfrac{\mathbf{k}_{1,i}}{4}, t_i + \dfrac{h_i}{4}\right) \\ \mathbf{k}_{3,i} &= h_if\left(\mathbf{x}_i + \dfrac{3\mathbf{k}_{1,i}}{32} + \dfrac{9\mathbf{k}_{2,i}}{32}, t_i + \dfrac{3h_i}{8}\right) \\ \mathbf{k}_{4,i} &= h_if\left(\mathbf{x}_i + \dfrac{1932\mathbf{k}_{1,i}}{2197} - \dfrac{7200\mathbf{k}_{2,i}}{2197} + \dfrac{7296\mathbf{k}_{3,i}}{2197}, t_i + \dfrac{12h_i}{13}\right) \\ \mathbf{k}_{5,i} &= h_if\left(\mathbf{x}_i + \dfrac{439\mathbf{k}_{1,i}}{216} - 8\mathbf{k}_{2,i} + \dfrac{3680\mathbf{k}_{3,i}}{513} - \dfrac{845\mathbf{k}_{4,i}}{4104}, t_i + h_i\right) \\ \mathbf{k}_{6,i} &= h_if\left(\mathbf{x}_i - \dfrac{8\mathbf{k}_{1,i}}{27} + 2\mathbf{k}_{2,i} - \dfrac{3544\mathbf{k}_{3,i}}{2565} + \dfrac{1859\mathbf{k}_{4,i}}{4104} - \dfrac{11\mathbf{k}_{4,i}}{40}, t_i + \dfrac{h_i}{2}\right) \\ \mathbf{X}_{1, i} &= \mathbf{x}_i + \dfrac{25\mathbf{k}_{1,i}}{216} + \dfrac{1408\mathbf{k}_{3,i}}{2565} + \dfrac{2197\mathbf{k}_{4,i}}{4104} - \dfrac{\mathbf{k}_{5,i}}{5} \\ \mathbf{X}_{2, i} &= \mathbf{x}_i + \dfrac{16\mathbf{k}_{1,i}}{135} + \dfrac{6656\mathbf{k}_{3,i}}{12825} + \dfrac{28561\mathbf{k}_{4,i}}{56430} - \dfrac{9\mathbf{k}_{5,i}}{50}+\dfrac{2\mathbf{k}_{6,i}}{55} \\ \mathbf{R}_i &= \dfrac{|\mathbf{X}_{1,i} - \mathbf{X}_{2,i}|}{h_i} \\ \mathbf{S}_i &= \left[\dfrac{\epsilon}{2\mathbf{R}_i}\right]^{1/4}\\ r_i &= \max{\mathbf{R}_i} \\ s_i &= \min{\mathbf{S}_i} \\ h_i &= s_ih_i. \end{aligned}

If riϵr_i \leq \epsilon , we let X1,i\mathbf{X}_{1,i} be our value of xi+1\mathbf{x}_{i+1}, hi+1h_{i+1} be hih_i, increment ii by 1, and proceed to the next step. Otherwise, we repeat the calculation with our updated step size. In the Ri\mathbf{R}_i calculation, v|\mathbf{v}| denotes a vector whose elements are the absolute value of the elements of v\mathbf{v}, not its vector magnitude. Here rir_i is the maximum error estimate we have for step ii.

hih_i can become unmanageably small if the problem one is solving is too numerically unstable. This can be seen in the double elastic pendulum solver webpage if you reduce ϵ\epsilon to too small a value or increase tft_f too much.