# Converting a System of Differential Equations into a First-Order System

I'm having a little bit of trouble converting the following system of differential equations into a first-order system $\dot z = f(z,u)$ for some vector $z$:

$$(M + m)\ddot x - ml\dot \theta^2\sin\theta + ml\ddot\theta\cos\theta = u$$ $$m\ddot x\cos\theta + ml\ddot\theta = mg\sin\theta$$

Here's what I've done so far: I thought I would try letting $$w_1 = x \implies w_1' = \dot x = w_2$$ $$w_2 = \dot x \implies w_2' = \ddot x = {ml\dot\theta^2\sin\theta - ml\ddot\theta\cos\theta + u \over M + m}$$ and $$z_1 = \theta \implies z_1' = \dot \theta = z_2$$ $$z_2 = \dot\theta \implies z_2' = \ddot\theta = {mg\sin\theta - m \ddot x \cos\theta \over ml}$$

Which substitution will give us $$z_2' = {mg\sin(z_1) - mw_2'\cos(z_1) \over ml}$$ $$w_2' = {mlz_2^2\sin(z_1) - mlz_2'\cos(z_1) +u \over M + m}$$

But I'm not sure this was even the correct thing to do. I now have a differential equation with my variables of interest in sines and cosines, which I don't think is correct.

Can someone provide me a little bit of help on the correct way to approach this problem?

• You need to solve the linear system for $(\ddot x,\ddot θ)$. Sep 22, 2016 at 12:44
• Are these Euler-Lagrange equations of a physical system with given Lagrangian function (basically the difference between kinetic and potential energy)? If so, there is a very standard way of doing this and getting additional helpful information. Sep 23, 2016 at 3:40

There is a standard way to transform a $n$th order differential equation in a system of $n$ first order equation. In your case, since you have two second order equation the system contains four equations.
$$\begin{cases} \dot x=y\\ \dot \theta=\phi\\ (M+m)\dot y -ml \dot \theta^2 \sin \theta+ml\dot \phi \cos \theta=u\\ m\dot y \cos \theta + ml\dot \phi=mg\sin \theta \end{cases}$$
OK, so according to my calculations, your system is the Euler-Lagrange system of equations given by the Lagrangian function $$\mathcal{L}(x, \theta, \dot{x}, \dot{\theta}) = \frac{M+m}{2} \, \dot{x}^2 + ml\,\cos{\theta}\,\, \dot{x}\,\dot{\theta} + \frac{ml^2}{2} \, \dot{\theta}^2 + u\, x - mgl \, \cos{\theta}$$ Compute $$\frac{\partial \mathcal{L}}{\partial \dot{x}} = (M+m) \, \dot{x} + ml \,\dot{\theta} \cos{\theta}$$ $$\frac{\partial \mathcal{L}}{\partial \dot{\theta}} = ml \, \dot{x} \cos{\theta + ml^2\, \dot{\theta}}$$ $$\frac{\partial \mathcal{L}}{\partial {x}} = u$$ $$\frac{\partial \mathcal{L}}{\partial {\theta}} = - \, ml \, \dot{x}\, \dot{\theta} \sin{\theta} + mgl \, \sin{\theta}$$ The Euler-Legrange equations are \begin{align} \frac{d}{dt}\left(\frac{\partial \mathcal{L}}{\partial \dot{x}}\right) &= \frac{\partial \mathcal{L}}{\partial {x}} \\ \frac{d}{dt}\left(\frac{\partial \mathcal{L}}{\partial \dot{\theta}} \right) &= \frac{\partial \mathcal{L}}{\partial {\theta}} \end{align} or written explicitly
\begin{align} &\frac{d}{dt}\left((M+m) \, \dot{x} + ml \,\dot{\theta} \cos{\theta}\right) = u \\ &\frac{d}{dt}\left(ml \, \dot{x} \cos{\theta + ml^2\, \dot{\theta}}\right) = - \, ml \, \dot{x}\, \dot{\theta} \sin{\theta} + mgl \, \sin{\theta} \end{align} which after differentiation in the left hand side become \begin{align} &(M+m) \, \ddot{x} - ml \,\dot{\theta}^2 \sin{\theta} + ml \,\ddot{\theta} \cos{\theta} = u \\ &ml \, \ddot{x} \cos{\theta} - ml \,\dot{x} \, \dot{\theta} \sin{\theta} + ml^2\, \ddot{\theta}= - \, m l \, \dot{x}\, \dot{\theta} \sin{\theta} + mgl \, \sin{\theta} \end{align} They reduce to \begin{align} &(M+m) \, \ddot{x} - ml \,\dot{\theta}^2 \sin{\theta} + ml \,\ddot{\theta} \cos{\theta} = u \\ &m \, \ddot{x} \cos{\theta} + ml\, \ddot{\theta} = mg \, \sin{\theta} \end{align} With this structure in mind we switch to Hamiltonian formulation. Define the conjugate momenta \begin{align} p_x = \frac{\partial \mathcal{L}}{\partial \dot{x}} &= (M+m) \, \dot{x} + ml \,\dot{\theta} \cos{\theta}\\ p_{\theta} = \frac{\partial \mathcal{L}}{\partial \dot{\theta}} &= ml \, \dot{x} \cos{\theta + ml^2\, \dot{\theta}} \end{align} Solve this linear system with respect to $\dot{x}, \dot{\theta}$ obtaining