# Dynamic model of an inverted pendulum (part 5)

This page is part of a serie of articles on how to write the model of an inverted pendulum. We strongly recommand to read the previous pages for a better understanding.

## Solving the system

Based on the previous equations, we can formulate $$\lambda_4$$ and $$\lambda_5$$:

$$\begin{array}{r c l} \lambda_4 &=& m_2.\ddot{x_2} \\ \lambda_5 &=& m_2.\ddot{y_2} + g.m_2 \\ \end{array}$$

The previous equations becomes:

$$\begin{array}{r c l} m_1.\ddot{x_1} &=& | \vec{F_t} | -m_2.\ddot{x_2} \\ I_2.\ddot{\Theta_2} &=& m_2.\ddot{x_2}.L.cos(\Theta_2) + (m_2.\ddot{y_2} + g.m_2).L.sin(\Theta_2) \end{array}$$

Thanks to the previous constraints on acceleration:

$$\begin{array}{r c l} m_1.\ddot{x_1} &=& | \vec{F_t} | -m_2.(\ddot{x_1} - L.\ddot{\Theta_2}.cos(\Theta_2) - L.\dot{\Theta_2}^2.sin(\Theta_2) ) \\ I_2.\ddot{\Theta_2} &=& m_2.(\ddot{x_1} - L.\ddot{\Theta_2}.cos(\Theta_2) + L.\dot{\Theta_2}^2.sin(\Theta_2) ).L.cos(\Theta_2) \\ &+& (m_2.(-L.\ddot{\Theta_2}.sin(\Theta_2) - L.\dot{\Theta_2}^2.cos(\Theta_2)) + g.m_2).L.sin(\Theta_2) \end{array}$$

Rewriting the previous equation gives us:

$$\begin{array}{r c l} (m_1+m_2).\ddot{x_1} &-& m_2.L.cos(\Theta_2).\ddot{\Theta_2} &=& | \vec{F_t} | - m_2.L.\dot{\Theta_2}^2.sin(\Theta_2) \\ -m_2.L.cos(\Theta_2).\ddot{x_1} &+& (I_2+ m_2.L^2).\ddot{\Theta_2} &=& m_2.g.L.sin(\Theta_2) \end{array}$$

and:

$$\begin{pmatrix} m_1+m_2 & - m_2.L.cos(\Theta_2) \\ -m_2.L.cos(\Theta_2) & (I_2+ m_2.L^2) \end{pmatrix} . \ddot{q} = \begin{pmatrix} | \vec{F_t} | - m_2.L.\dot{\Theta_2}^2.sin(\Theta_2) \ m_2.g.L.sin(\Theta_2) \end{pmatrix}$$

The general equation of the system is:

$$\ddot{q}=A^{-1}.B$$

where:

$$A=\begin{pmatrix} m_1+m_2 & - m_2.L.cos(\Theta_2) \\ -m_2.L.cos(\Theta_2) & (I_2+ m_2.L^2) \end{pmatrix}$$

$$B= \begin{pmatrix} | \vec{F_t} | - m_2.L.\dot{\Theta_2}^2.sin(\Theta_2) \ m_2.g.L.sin(\Theta_2) \end{pmatrix}$$