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$
Find an analytic expression for $x(t)$? (Hint: use the substitution $y(t) = x(t) \exp({\frac{-t^2}{2}})$)
Compute an approximate solution $x(h)$ for one RK4 iteration with step size h neglecting terms at $O(h^6)$.
Hint:
$x(t) = c_1 e^{\frac{t^2}{2}}-1$,
Mathematica gives the following. It remains to compute it:
$$x'(t) = f(t, x) = t (x(t)+1), x(0) = 0$$ $$x_{n + 1} = x_n + k_1/6+k_2/3+k_3/3+k_4/6$$ $$t_{n + 1} = t_n + h$$ $$k_1 = h f(t_n, x_n)$$ $$k_2 = h f(t_n + h/2, x_n + (h k_1)/2)$$ $$k_3 = h f(t_n + h/2, x_n + (h k_2)/2)$$ $$k_4 = h f(t_n + h, x_n + h k_3)$$ $$x_0 = 0$$ $$t_0 = 0$$