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?
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} $$