[Math] 4th order Runge-Kutta method

numerical methodsordinary differential equationsrunge-kutta-methods

I am struggling with the following question regarding the 4th order Runge-Kutta method. I wish to find an approximate solution to the ODE:

$$\frac{dx}{dt} = f(x)$$

using the 4th Order Runge Kutta method:

$$\begin{aligned} k_1 &= h f(x(t), t)\\ k_2 &= h f(x(t) + \frac{k_1}{2}, t + \frac{h}{2})\\ k_3 &= hf(x(t) + \frac{k_2}{2}, t + \frac{h}{2})\\ k_4 &= hf(x(t) + k_3, t + h)\end{aligned}$$

$$x(t + h) = x(t) + \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)$$

If $x(t)$ obeys the ODE:

$$\frac{dx}{dt} = (x + 1)t$$

with initial condition $x(0) = 0$

  1. Find an analytic expression for $x(t)$? (Hint: use the substitution $y(t) = x(t) \exp({\frac{-t^2}{2}})$)

  2. Compute an approximate solution $x(h)$ for one RK4 iteration with step size h neglecting terms at $O(h^6)$.

Best Answer

You have an ODE $$ \frac{dx}{dt} = f(t,x) = (x+1)t $$ which separates to $$ \frac{dx}{x+1} = tdt\\ \log |x+1| + C = \frac{t^2}{2}\\ x = C_1 e^{t^2/2} - 1. $$ With $x(0) = 0$ that gives $C_1 = 1$ and $$ x(t) = e^{t^2/2} - 1. $$

Computing the first step we get $$\begin{aligned} k_1 &= hf(0, 0) = 0\\ k_2 &= hf\left(\frac{h}{2}, \frac{k_1}{2}\right) = h\frac{h}{2}\\ k_3 &= hf\left(\frac{h}{2}, \frac{k_2}{2}\right) = h\frac{h(h^2 + 4)}{8}\\ k_4 &= hf\left(h, k_3\right) = h\frac{h(8+4h^2+h^4)}{8}\\ x_{1} &= \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4) = \frac{1}{48} h^2 \left(h^4+6 h^2+24\right) = \\ &= \frac{h^2}{2} + \frac{h^4}{8} + O(h^6). \end{aligned} $$ And the exact solution is $$ x(h) = e^{h^2/2} - 1 = \frac{h^2}{2} + \frac{h^4}{8} + O(h^6). $$ This agrees with the fact that method is of fourth order, thus the local truncation error is $O(h^5)$.