# Runge-Kutta 4th order method (RK4) for second order Diff Eq

## Homework Statement

Hello, maybe this is due to my lack of understand of RK4, but I have an equation: x'' + b^2*x=0 (derivatives with respect to variable t) and I need to use RK4 to find the solution on an interval. I can readily find solutions analytically, but my understanding of RK4 is that I need the problem in a first order diff eq, which I do not accomplish when I use characteristic equations. Initial conditions are x(t)=0 and x'(0)=0. The intervals is 0 to 4$\pi$ and step sizes of h.

## Homework Equations

Find diff eq, such that y'=f(t,y)

RK4 equations:
yn+1= yn + h/6*(k1 + 2*k2 + 2*k3 + k4)

k1=f(tn,yn)

k2=f(tn+h/2,yn+k1*h/2)

k3=f(tn+h/2,yn+k2*h/2)

k4=f(tn+h,yn+k3*h)

## The Attempt at a Solution

My attempt to break the problem to first order is a substitution with x'=v

And it follows that that: v'= -b^2*x = f(t,x).

Now I have two first order differential equations. I can use RK4 to get values for v and x, but it seems like my values of v depend on x and vice verse? Here is what I have so far, but it is coupled so I think it's wrong.

First I solved for the higher ordered one, aka v. So:

vn+1 = vn + 1/6*(l1 + 2*l2 + 2*l3 +l4).

Where:

l1= -b^2*xn*h
l2= -b^2*xn*h*(1+h/2)
l3= -b^2*xn*h*(1+h/2+h2/4)
l4= -b^2*xn*h*(1+h/2+h2/2+h3/4)

Now I solved for x with the following:

xn+1 = xn + 1/6*(k1 + 2*k2 + 2*k3 + k4)

Where:
k1= vn*h
k2= vn*h*(1+h/2)
k3= vn*h*(1+h/2+h2/4)
k4= vn*h*(1+h/2+h2/2+h3/4)

Is this right? Since I have initial conditions I think I can build this up to the full solution since I know v0 and x0.

Last edited:

DrClaude
Mentor
Sorry to say, but you got it all wrong! The point is to solve both equations at the same time, and use the intermediate solutions to get a better guess for the next intermediate solution, and when you have all 4 of them you take an "average" to actually advance one time step.

Check this thread for more details: