# State space linearization of an inverted pendulum

## Inverted pendulum

An inverted pendulum on a cart is as shown in the figure.

The system dynamics defined by Newton's second law of motion can be written as the following set of equations.

\begin{align} \ddot{p} &= \frac{\dot{\theta}^{2} m L \sin \theta-\frac{3}{4} m g \sin \theta \cos \theta+u}{M+m-\frac{3}{4} m \cos ^{2} \theta} \\ \ddot{\theta} &= \frac{\frac{3 g}{4 L}(M+m) \sin \theta-\frac{3 m}{4} \dot{\theta}^{2} \sin \theta \cos \theta-\frac{3}{4 L} u \cos \theta}{M+m-\frac{3}{4} m \cos ^{2} \theta} \end{align}

Given the dynamics, the state vector can be chosen to be the positions & velocities.

$\mathbf{x}=\left[ \begin{array}{c}{\theta} \\ {\dot{\theta}} \\ {p} \\ {\dot{p}}\end{array}\right]=\left[ \begin{array}{c}{x_{1}} \\ {x_{2}} \\ {x_{3}} \\ {x_{4}}\end{array}\right]$

The nonlinear state equations as functions of the states and inputs

\begin{aligned} \dot{\mathbf{x}} &=\mathbf{f}(\mathbf{x}, u) \\ y &=g(\mathbf{x}, u) \end{aligned}

can be written as,

\begin{align} \mathbf{\dot{x}} = \left[ \begin{array}{c}\dot{\theta} \\ {\ddot{\theta}} \\ \dot{p} \\ {\ddot{p}}\end{array}\right] &= \left[ \begin{array}{c}{x_{2}} \\ \frac{\frac{3 g}{4 L}(M+m) \sin x_{1}-\frac{3 m}{4} \sin x_{1} \cos x_{1} \cdot x_{2}^{2}-\frac{3}{4 L} \cos x_{1} \cdot u}{M+m-\frac{3}{4} m \cos ^{2} x_{1}} \\ x_{4} \\ \frac{m L \sin x_{1} \cdot x_{2}^{2}-\frac{3}{4} m g \sin x_{1} \cos x_{1}+u}{M+m-\frac{3}{4} m \cos ^{2} x_{1}} \end{array}\right] \\ y = p &= x_{3} \end{align}

The state equations above are description of a nonlinear system due to the sine and cosine values. The stationary state is selected as $\mathbf{x}_{0}=\left[ \begin{array}{llll}{0} & {0} & {0} & {0}\end{array}\right]^{T}$ and these nonlinearities can be linearly approximated by assuming that $\sin \theta \cong \theta, \cos \theta \cong 1$ and $\dot{\theta}^{2} \cong 0$

Substituting these values in the state equations gives,

\begin{align} \dot{x}_{2} &= \ddot{\theta} \cong \frac{\frac{3 g}{4 L}(M+m) \theta-\frac{3}{4 L} u}{M+\frac{m}{4}} \\ \dot{x}_{4} &= \ddot{p} \cong \frac{-\frac{3}{4} m g \theta+u}{M+\frac{m}{4}} \end{align}

At the stationary point calculating the Jacobian matrix, the partial derivatives of the state equations with respect to the states and inputs, will give the linearized state equation where $\Delta$ variables are perturbation from the stationary point.

\begin{align} \dot{\Delta x} &= \left[ \begin{array}{cccc} 0 & 1 & 0 & 0 \\ \frac{3 g(M+m)}{\left(M+\frac{m}{4}\right) 4 L} & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \frac{-\frac{3}{4} m g}{M+\frac{m}{4}} & 0 & 0 & 0 \end{array} \right] \Delta \mathbf{x}+ \left[ \begin{array}{c} 0 \\ \frac{-\frac{3}{4 L}}{M + \frac{m}{4}} \\ 0 \\ {\frac{1}{M+\frac{m}{4}}} \end{array}\right] \Delta \mathbf{u} \\ \Delta y &= \left[ \begin{array}{llll}{0} & {0} & {1} & {0}\end{array}\right] \Delta \mathbf{x} \end{align}