# Thread: Solving Second Order Differential Equations using Runge Kutta

1. ## Solving Second Order Differential Equations using Runge Kutta

1. The problem statement, all variables and given/known data
In aerodynamics, one encounters the following initial value problem for Airy’s equations:

y''(x) + xy = 0, y(0) = 1, y'(0) = 0

Using the Runge-Kutta method with h=0.005 and determine values between x=0 and x=10 sufficient to sketch the relationship.

2. Relevant equations
y''(x) + xy = 0, y(0) = 1, y'(0) = 0
I think,
k1 = h*f(Xn, Yn)
k2 = h*f(Xn+h/2, Yn+k1/2)
k3 = h*f(Xn+h/2, Yn+k2/2)
k4 = h*f(Xn + h, Yn + k3)

3. The attempt at a solution
From what I have read you cant do second order ODE using runge kutta without breaking it into a system of first order ODEs so thats what I tried.

I tried:
d2y/dx2 + xy = 0

dy/dx = z, y(0) = 1

dz/dx + xy = 0

dz/dx = -xy, z(0) = 0

I dont know if that is right or not and if it is I have no idea where to go from here.

Thanks for any help.

2. There's nothing wrong with your change to a system. It'll work fine. You now need to figure out, in the RK4 method, what quantities are vectors and what quantities are scalars, and what's what.

What is your f?

3. I am doing this all in MATLAB, This is what I have come up with but I am not sure if this is correct or not.

Attached are my MATLAB code, a Graph of the results, and an excel sheet of all results.
the matlab code can be opened in notepad.

Thanks for any help.
MEA Proj.zip

4. Hmm. Well, I'm not a MATLAB expert, by any means. Captain Black (CB) is one of the best on the MHF for that. So we could either ask CB to look at the problem, or you could translate your code into mathematical equations. Your choice.

5. All the code does is loop through these equations for each value of X.

$\displaystyle x_{n+1}\equiv x_n+h$

$\displaystyle z_{n+1,1}\equiv z_{n,1}+\frac{1}{6}\left(k_{1,1}+2k_{2,1}+2k_{3,1} +k_{4,1}\right)$

$\displaystyle z_{n+1,2}\equiv z_{n,2}+\frac{1}{6}\left(k_{1,2}+2k_{2,2}+2k_{3,2} +k_{4,2}\right)$

where:

$\displaystyle k_{1,1}\equiv hz_{n,2}$

$\displaystyle k_{1,2}\equiv -hx_nz_{n,1}$

$\displaystyle k_{2,1}\equiv h\left(z_{n,2}+\frac{1}{2}k_{1,2}\right)$

$\displaystyle k_{2,2}\equiv -h\left(x_n+\frac{h}{2}\right)\left(z_{n,1}+\frac{1 }{2}k_{1,2}\right)$

$\displaystyle k_{3,1}\equiv h\left(z_{n,2}+\frac{1}{2}k_{2,2}\right)$

$\displaystyle k_{3,2}\equiv -h\left(x_n+\frac{h}{2}\right)\left(z_{n,1}+\frac{1 }{2}k_{2,2}\right)$

$\displaystyle k_{4,1}\equiv h\left(z_{n,2}+k_{3,2}\right)$

$\displaystyle k_{4,2}\equiv -h\left(x_n+h\right)\left(z_{n,1}+k_{3,2}\right)$

6. Ok, from what you've typed, I see three problems (or one problem, depending on how you look at it). You should have this:

$\displaystyle k_{2,2}\equiv -h\left(x_n+\frac{h}{2}\right)\left(z_{n,1}+\frac{1 }{2}k_{1,1}\right)$ and

$\displaystyle k_{3,2}\equiv -h\left(x_n+\frac{h}{2}\right)\left(z_{n,1}+\frac{1 }{2}k_{2,1}\right)$ and

$\displaystyle k_{4,2}\equiv -h\left(x_n+h\right)\left(z_{n,1}+k_{3,1}\right),$

instead of what you have. The only difference is that I'm taking the second component of k at the far right of each equation. You did this correctly for $\displaystyle k_{1,1}$ and $\displaystyle k_{1,2},$ but not for the rest.

Everything else looks good to me.