# Solving 2nd ODE with Runge Kutta?

• Oct 7th 2010, 06:01 AM
chutsu
Solving 2nd ODE with Runge Kutta?
I have a simple pendulum that has equation:

$\ddot{\theta} + \omega^2 \sin{\theta} = 0$

My problem is that the examples I have come across in textbooks all refer the differential equation only on its first order, so what if I have a second order?

How should I implement it in runge kutta's method?

Thanks
• Oct 7th 2010, 06:29 AM
Ackbeet
• Oct 7th 2010, 03:02 PM
chutsu
so I have to reduce the 2nd order to a 1st order, by using reduction of orders technique?

can you show me how to do it?
• Oct 7th 2010, 04:50 PM
Ackbeet
It's not exactly called "reduction of order", even though it does reduce the order. "Reduction of order" is a different technique.

What you do here is define a vector solution to the problem:

Let $x_{1}(t)=\theta(t),$ and let

$x_{2}(t)=\theta'(t).$ Then the differential equation becomes the system

$x_{1}'(t)=x_{2}(t)$
$x_{2}'(t)=-\omega^{2}\sin(x_{1}(t)).$

In this manner, I believe you can transform any nth degree ODE into a system of n first-order ODE's. Make sense?
• Oct 10th 2010, 02:37 PM
chutsu
no sorry, I feel like an idiot. So do I have to use the Runge Kutta twice for both first order differential equation? But How?
• Oct 11th 2010, 05:50 AM
Ackbeet
Quote:

So do I have to use the Runge Kutta twice for both first order differential equation?
No, you don't have to do that. I don't even think that would be a solution. No, instead, what you do is vectorize everything. If you look here, you will see the RK4 formulas.

Now, in those formulas, there's nothing that says that the $y_{n+1},$ the $f$, and the $y_{n}$ can't be vectors. You would still have $h$ be a scalar, because it's an increment in the independent variable. So, just to make everything explicit, let me write out the vector version of RK4 (vectors are in bold, scalars not in bold):

Given the ODE system

$\dot{\mathbf{x}}=\mathbf{f}(t,\mathbf{x}),\quad \mathbf{x}(t_{0})=\mathbf{x}_{0},$ the RK4 method for this problem is given by

$\displaystyle \mathbf{x}_{n+1}=\mathbf{x}_{n}+\frac{h}{6}\left(\ mathbf{k}_{1}+2\mathbf{k}_{2}+2\mathbf{k}_{3}+\mat hbf{k}_{4}\right)$

$t_{n+1}=t_{n}+h$

where $\mathbf{x}_{n+1}$ is the RK4 approximation of $\mathbf{x}(t_{n+1}),$ and

$\mathbf{k}_{1}=\mathbf{f}(t_{n},\mathbf{x}_{n})$

$\displaystyle \mathbf{k}_{2}=\mathbf{f}\left(t_{n}+\frac{h}{2},\ mathbf{x}_{n}+\frac{h}{2}\,\mathbf{k}_{1}\right)$

$\displaystyle \mathbf{k}_{3}=\mathbf{f}\left(t_{n}+\frac{h}{2},\ mathbf{x}_{n}+\frac{h}{2}\,\mathbf{k}_{2}\right)$

$\displaystyle \mathbf{k}_{4}=\mathbf{f}\left(t_{n}+h,\mathbf{x}_ {n}+h\,\mathbf{k}_{3}\right).$

If you examine these equations carefully, you'll see that all the multiplications are defined: scalar multiplication of a vector. That plus function evaluations gives you everything you need. Don't forget that your ODE/function evaluation is

$\dot{\mathbf{x}}(t)=\begin{bmatrix}\dot{x}_{1}(t)\ \ \dot{x}_{2}(t)\end{bmatrix}=\mathbf{f}(t,\mathbf{x })=\begin{bmatrix}x_{2}(t)\\-\omega^{2}\sin(x_{1}(t))\end{bmatrix}.$

Does that make things clearer?