# Solving constrained odes's using inbuilt solvers in Matlab/Octave

I would like to solve a set of coupled second order differential equations using inbuilt Matlab/Octave subroutines. These equations arise when trying to model sliding of mass ($$m_2$$) over a wedge of mass ($$m_1$$) under gravity and neglecting friction on all sliding surfaces. The equations are of the form: $$\begin{bmatrix}m_1&0&\sin \theta \\0&m_2&-\sin \theta \\ m_2\tan \theta & -m_2\tan \theta & -\cos \theta \end{bmatrix}\begin{bmatrix}\ddot{x}_1 \\ \ddot{x}_2\\N\end{bmatrix}= \begin{bmatrix}0\\0\\-m_2g\end{bmatrix}$$ subject to initial conditions $$x_1(0)=\dot{x}_1(0)=0,x_2(0)=\dot{x}_2(0)=0,x_1(0)=\dot{x}_1(0)=0$$ Here $$x_1$$ and $$x_2$$ denote the x-displacement of the wedge and the block, respectively and $$N$$ denotes the (unknown) normal forces between the block and the wedge and $$\theta$$ denotes the wedge angle.
Rewriting the equations as a set of single order odes's, I get $$\begin{bmatrix} 1&0&0&0&0\\ 0&m_1&0&0&\sin \theta \\ 0&0&1&0&0\\ 0&0&0&m_2&-\sin\theta \\ 0&m_2\tan \theta &0&-m_2\tan \theta & -\cos\theta \end{bmatrix} \begin{bmatrix} \dot{y}_1\\\dot{y}_2\\\dot{y}_3\\\dot{y}_4\\N \end{bmatrix} = \begin{bmatrix} y_2\\0\\y_4\\0\\-m_2g \end{bmatrix}$$ I would like to know if one can solve a set of such equations using Matlab/Octave. Note that I specifically want to retain $$N$$ and do not wish to eliminate it by manipulating the equations. Thank you.

Yes you can. If the term that multiplies $$N$$ is never zero, then $$N$$ is an algebraic variable of index 1. Its combination with the ODEs on $$x$$ yields a system of differentiel-algebraic equations (DAEs). Matlab has some dedicated solvers, specialised from ODE solvers. The previous link also gives some basics on DAEs.