# Thread: Fourth-order Runge-Kutta for this equation.

1. ## Fourth-order Runge-Kutta for this equation.

Hi,

For my 3rd year project I'm meant to code different O.D.E solving algorithms and run them on GPU and compare the results to running them on CPU.

The first algorithm I am meant to code is the fourth order Runge-Kutta for a O.D.E in the form:
dx/dt = ax(t), x0 = 0 (I think that is how it is written)

It's solution is meant to be in the form of x = e^(at)x0 (again, I think)

Could someone show me how to set up the runge kutta algorithm? I am totally confused about the t and the x in the Runge-Kutta equation.

2. Originally Posted by kenny
Hi,

For my 3rd year project I'm meant to code different O.D.E solving algorithms and run them on GPU and compare the results to running them on CPU.

The first algorithm I am meant to code is the fourth order Runge-Kutta for a O.D.E in the form:
dx/dt = ax(t), x0 = 0 (I think that is how it is written)

It's solution is meant to be in the form of x = e^(at)x0 (again, I think)

Could someone show me how to set up the runge kutta algorithm? I am totally confused about the t and the x in the Runge-Kutta equation.
We have an ODE of the form:

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

Because $\displaystyle t$ does not appear explicitly on the right-hand-side of the ODE the equations for the 4-order RK algorithm become:

$\displaystyle x_{n+1}=x_n+\frac{h}{6}(k_1+2k_2+2k_3+k_4)$

with:

$\displaystyle k_1=f(x_n)$
$\displaystyle k_2=f(x_n+hk_1/2)$
$\displaystyle k_3=f(x_n+hk_2/2)$
$\displaystyle k_4=f(x_n+hk_3)$

Where $\displaystyle x_n=x(nh)$, so we start from $\displaystyle x_0=x(0)=0$ and step forward from there.

The full equations for 4-order RK can be found on the Wikipedia page.

CB