0
$\begingroup$

I am struggling with this 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:

$$k_1 = hf(x(t), t)$$

$$k_2 = hf(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)$$

$$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$$

(i) Find an Analytic Expression for x(t)?

(Hint: use the substitution $y(t) = x(t) \exp({\frac{-t^2}{2}})$)

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

$\endgroup$
1
$\begingroup$

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)$.

$\endgroup$
0
$\begingroup$

Hint:

  1. $x(t) = c_1 e^{\frac{t^2}{2}}-1$,

  2. 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$$

$\endgroup$
0
$\begingroup$

Runge-Kutta Method is a way to generate a iterative sequence. So I'll treat x(0)=0 as $x_0 = 0$

Let h = 0.5;(thus $\frac{h}{2}=0.25$); $$x_{n+1} = x_n + (0.5) [\frac{1}{6}(k_1+2 k_2 + 2 k_3 + k_4)]$$ $$k_1=(0.5)[(0+1)0]=0$$ $$k_2=(0.5)[(0+\frac{0}{2}+1)(0+0.25)]=0.125$$ $$k_3=(0.5)[(0+\frac{0.125}{2}+1)(0+0.25)]=0.1328125$$ $$k_4=(0.5)[(0+0.132813+1)(0+0.5)]=0.283203125$$ Thus, $$x_1=0 + (0 + 2*0.125 + 2*0.1328125 + 0.283203125)/6 =0.13313802083333331 $$ Furthermore: $$x_2=0.6485277017, x_3 = 2.07797616, x_4=6.366803294$$ Ergo, the function's approximations would be the following: $$f(0)=0, f(0.5)=0.13,f(1)=0.65,f(1.5) = 2.08, f(2)=6.37 $$ I made this spreadsheet; you can change the value of h for a more accurate approximation.

https://docs.google.com/spreadsheets/d/123WKM1Z8sKnFleduDqz3V9wAahRQzBKygStuykCX3hM/edit?usp=sharing

4th Order Runge Kutta is pretty straight forward, its even easier to set up if you used a computer program. I also included the Euler method; it is much simpler to understand.

$\endgroup$
  • 1
    $\begingroup$ While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. $\endgroup$ – user251257 Aug 26 '15 at 2:11
  • $\begingroup$ I edited my post to include the essential parts of the answer $\endgroup$ – Michael Maliszesky Aug 26 '15 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.