# 4th order RK to solve 2nd order ODE

Tags:
1. Dec 2, 2016

### Kanashii

1. The problem statement, all variables and given/known data
Consider the initial value problem x" + x′ t+ 3x = t; x(0) = 1, x′(0) = 2 Convert this problem to a system of two first order equations and determine approximate values of the solution at t=0.5 and t=1.0 using the 4th Order Runge-Kutta Method with h=0.1.
2. Relevant equations
yn+1 = yn + 1/6 ( k1 + 2k2 + 2k3 + k4)
k1 = h* f(xn, yn)
k2 = h* f(xn + 1/2 h, yn + 1/2 k1)
k3 = h* f(xn + 1/2 h, yn + 1/2 k2)
k4 = h* f(xn+1, yn+k3)
3. The attempt at a solution
I tried to convert the equation into two linear ODEs:

x = x1
x′= x1' = x2
x′′= x1'' = x2'

x2' = -x2 t + t - 3x1 (first linear ODE)
x1' = x2 (second linear ODE)

I do not know what to do from here.
From 4th Order RK equations, I do not know what f(xn, yn) is.

Last edited by a moderator: Dec 2, 2016
2. Dec 2, 2016

### eys_physics

The Runge-Kutta method give the solution to the differential equation:
$$x'(t)=f(x,t)$$

This can also be generalized to several equations by allowing $x(t)$ and $f(x,t)$ being vectors, i.e. $x=(x_1,x_2,...,x_n)$ and $f=(f_1,f_2,...,f_n)$. So, in your case $f=(f_1,f_2)$ is a two-dimensional array containing the right-hand side of each equation.

By the way, I recommend that you use Latex to write your equations. In your post it is difficult to read them.

3. Dec 2, 2016

### Ray Vickson

See
http://math.stackexchange.com/quest...-order-method-on-a-system-of-2-first-order-od
for a detailed explanation plus worked example.

BTW: I do not agree that your work is difficult to read; in fact, it reads surprisingly well and looks quite good. However, post #2 is correct in suggesting the use of LaTeX; you would find it much easier and faster than constantly using the [ S U B] ... [/ S U B] construction, and it wold look even better than what you have already.

4. Dec 2, 2016

### epenguin

Some of the ' need to be outside of the [ SUB] ' [/SUB]

5. Dec 2, 2016

### Staff: Mentor

I moved them, so it should be OK now.