Inverted Pendulum
An inverted pendulum on a cart consists of a mass \(m\) at the top of a pole of length \(l\) pivoted on a horizontally moving base as shown in the adjacent.
The objective of the control system is to balance the inverted pendulum by applying a force to the cart that the pendulum is attached to.
Modeling

\(M\): mass of the cart
\(m\): mass of the load on the top of the rod
\(l\): length of the rod
\(u\): force applied to the cart
\(x\): cart position coordinate
\(\theta\): pendulum angle from vertical
Using Lagrange’s equations:
See this link for more details.
So
Linearized model when \(\theta\) small, \(cos{\theta} \approx 1\), \(sin{\theta} \approx \theta\), \(\dot{\theta}^2 \approx 0\).
State space:
where
If control only theta
If control x and theta
LQR control
The LQR controller minimize this cost function defined as:
the feedback control law that minimizes the value of the cost is:
where:
and \(P\) is the unique positive definite solution to the discrete time algebraic Riccati equation (DARE):

MPC control
The MPC controller minimize this cost function defined as:
subject to:
Linearized Inverted Pendulum model
Initial state
