# Coupled 2nd Order DE: Convert to system of 1st Order

1. Apr 30, 2013

### jstluise

It's been a while since I've played with systems of ODEs, and I seem to have forgotten some of the tricks. As an example, I have two coupled nonlinear DE that I want to convert to a system of four 1st order nonlinear DE. But, the normal way of making variable substitutions is not working of me.

Two 2nd order nonlinear DE:
$\ddot{\alpha} + \ddot{\beta}cos(\alpha-\beta)+\dot{\beta}^2sin(\alpha-\beta)=\tau_{1}$
$\ddot{\beta} + \ddot{\alpha}cos(\alpha-\beta)-\dot{\alpha}^2sin(\alpha-\beta)=\tau_{2}$

If I substitute variables $x_1=\alpha$, $x_2=\dot{\alpha}$,$x_3=\beta$,$x_4=\dot{\beta}$, like my initial reaction was, I get:

$\dot{x_1}=x_2$
$\dot{x_2}=-\dot{x_4}cos(x_1-x_3)-x_4^2sin(x_1-x_3)+\tau_1$
$\dot{x_3}=x_4$
$\dot{x_4}=-\dot{x_2}cos(x_1-x_3)+x_2^2sin(x_1-x_3)+\tau_2$

which isn't quite right, since it is not in the form $\dot{\vec{\textbf{x}}}=\vec{\textbf{f}}(t,\vec{\textbf{x}})$

I'm trying to get it a form where I can run it through ODE45 or a similar solver.

Refresh my memory! :)

EDIT! I believe I figured it out. I did do it right, just implementing it in Matlab had me confused. But, all I have to do in my function is use the old values for $\dot{x_2}$ and $\dot{x_4}$. Seeing those derivatives in the rhs just threw me off. Is this the right way to go about it?

Last edited: Apr 30, 2013
2. Apr 30, 2013

### AlephZero

You can write your equations as
$$\begin{bmatrix} 1 & \cos(\alpha - \beta) \\ \cos(\alpha - \beta) & 1 \end{bmatrix} \begin{bmatrix} \ddot\alpha \\ \ddot\beta \end{bmatrix} = \begin{bmatrix} -\dot\beta^2 \sin(\alpha - \beta) + r_1 \\ \dot\alpha^2 \sin(\alpha - \beta) + r_2\end{bmatrix}$$
So
$$\begin{bmatrix} \ddot\alpha \\ \ddot\beta \end{bmatrix} = \begin{bmatrix} 1 & \cos(\alpha - \beta) \\ \cos(\alpha - \beta) & 1 \end{bmatrix}^{-1} \begin{bmatrix} -\dot\beta^2 \sin(\alpha - \beta) + r_1 \\ \dot\alpha^2 \sin(\alpha - \beta) + r_2\end{bmatrix}$$

The matrix is singular if $\alpha = \beta$, but in that case you only have one differential equation not two.

3. May 1, 2013

### jstluise

That makes sense, but is that the only way to implement it into Matlab (ode45)? I thought I was onto something (see my edit in my original post), but now I'm thinking it won't work.

4. May 1, 2013

### Staff: Mentor

Move everything with overdots to the left hand sides. Then re-express the left hand side as a matrix times the column vector of the dotted first derivatives. So the equation is

Mxdot=f(x,t)

In your subroutine for evaluating derivatives, first calculate the right hand side vector. Then premultiply it by the inverse of M. Some equation solvers accept the more general inputs as M and f(x,t), and do the inversion for you. I'm not sure whether the equation solver you are using will do this.

Chet

5. May 1, 2013

### jstluise

Thanks, Chet. Turns out I was able to keep it in my original form (system of implicit DEs) and use Matlabs ode15i solver. I believe it does a similar operation by inverting the matrix....but it just saves me a lot of work! It wouldn't be too bad, but when the system I have has 8 state variables, it gets messy really fast.

Anyways, looks like ode15i was the solution I was looking for.