# Runge Kutta on second order differential

• Jan 4th 2010, 10:17 PM
kenny
Runge Kutta on second order differential
Hi, As part of my project I have been asked to code a program that peforms the runge kutta 4th order algoritm on a equation of form:
$ax'' + bx' + c = 0$

The way I have been told to do this is use x_1 and x_2 and use them like this:
$ax'' + bx' + c = ax_1 +bx_2 +c$
and then perform the runge Kutta algoritm on x_1 and x_2 serperately.

I haven't done anything on second order differentials for awhile now, could someone tell me how to set this up? Also is an initial condition needed? I think the solution is something like f(x) =e^(Ax).
• Jan 4th 2010, 10:52 PM
CaptainBlack
Quote:

Originally Posted by kenny
Hi, As part of my project I have been asked to code a program that peforms the runge kutta 4th order algoritm on a equation of form:
$ax'' + bx' + c = 0$

The way I have been told to do this is use x_1 and x_2 and use them like this:
$ax'' + bx' + c = ax_1 +bx_2 +c$
and then perform the runge Kutta algoritm on x_1 and x_2 serperately.

I haven't done anything on second order differentials for awhile now, could someone tell me how to set this up? Also is an initial condition needed? I think the solution is something like f(x) =e^(Ax).

What you do is reduce the second order ODE to a first order system or vector ODE, then use RK4 on that.

You proceed by introducing the state vector:

$\bold{X}=\left[\begin{array}{c}x_1\\x_2\end{array}\right]$

where $x_1=x$ and $x_2=x'$, then your ODE becomes:

$
\bold{X}'=\left[\begin{array}{c}x_1'\\x_2'\end{array}\right]=\left[\begin{array}{c}x_2\\-\frac{bx_2+c}{a}\end{array}\right]
$

CB
• Jan 5th 2010, 06:20 AM
kenny

I'm still not quite sure how I am going to set it up. I have found the piece of paper with my supervisors hints. He does this:
$x'' + 5x' + 6x = 0$
$x_1 = x, x_2 = x'$
$x_1' = x_2, x_2' = x'' = -5x_2 -6x_1$ (which is what you said basically)
and sets up x' = Ax, which has solution $e^(At)x_0$

This is the analytical solution and I understand it, but I'm kind of confused on the numerical methods way of doing it.

I think its meant to be RK4 on $x_1' = x_2$ and then on $x_2' = -5x_2 -6x_1$, but what do I do with these two outputs?

I'm fairly sure the original equation is only meant to have 1 output.
• Jan 5th 2010, 12:00 PM
CaptainBlack
Quote:

Originally Posted by kenny

I'm still not quite sure how I am going to set it up. I have found the piece of paper with my supervisors hints. He does this:
$x'' + 5x' + 6x = 0$
$x_1 = x, x_2 = x'$
$x_1' = x_2, x_2' = x'' = -5x_2 -6x_1$ (which is what you said basically)
and sets up x' = Ax, which has solution $e^(At)x_0$

This is the analytical solution and I understand it, but I'm kind of confused on the numerical methods way of doing it.

I think its meant to be RK4 on $x_1' = x_2$ and then on $x_2' = -5x_2 -6x_1$, but what do I do with these two outputs?

I'm fairly sure the original equation is only meant to have 1 output.

Have you used RK4 on a first order scalar ODE? You really need to have numerically integrated one of these before moving to the vector case.

CB
• Jan 5th 2010, 12:39 PM
kenny
Yes I managed to code RK4 for a 1st order ODE (dx/dt = 5x) to run on my GPU and generate the answers fairly accurately.
• Jan 12th 2010, 07:55 AM
kenny
Could anyone please tell step by step what my program needs to do? I'm still not really sure what it is meant to do.