- #1

- 19

- 0

## 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[itex]\pi[/itex] and step sizes of h.

## Homework Equations

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

RK4 equations:

y

_{n+1}= y

_{n}+ h/6*(k

_{1}+ 2*k

_{2}+ 2*k

_{3}+ k

_{4})

k

_{1}=f(t

_{n},y

_{n})

k

_{2}=f(t

_{n}+h/2,y

_{n}+k

_{1}*h/2)

k

_{3}=f(t

_{n}+h/2,y

_{n}+k

_{2}*h/2)

k

_{4}=f(t

_{n}+h,y

_{n}+k

_{3}*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:

v

_{n+1}= v

_{n}+ 1/6*(l

_{1}+ 2*l

_{2}+ 2*l

_{3}+l

_{4}).

Where:

l

_{1}= -b^2*x

_{n}*h

l

_{2}= -b^2*x

_{n}*h*(1+h/2)

l

_{3}= -b^2*x

_{n}*h*(1+h/2+h

^{2}/4)

l

_{4}= -b^2*x

_{n}*h*(1+h/2+h

^{2}/2+h

^{3}/4)

Now I solved for x with the following:

x

_{n+1}= x

_{n}+ 1/6*(k

_{1}+ 2*k

_{2}+ 2*k

_{3}+ k

_{4})

Where:

k

_{1}= v

_{n}*h

k

_{2}= v

_{n}*h*(1+h/2)

k

_{3}= v

_{n}*h*(1+h/2+h

^{2}/4)

k

_{4}= v

_{n}*h*(1+h/2+h

^{2}/2+h

^{3}/4)

Is this right? Since I have initial conditions I think I can build this up to the full solution since I know v

_{0}and x

_{0}.

Last edited: