Regulate an Inverted Pendulum

In this classic control systems problem, a controller is designed to stabilize a system about an unstable equilibrium. The inverted pendulum is linearized about the vertical position. StateFeedbackGains gives a matrix, which can be thought of as a controller, that places the poles of the system in the left half of the complex plane. The closed-loop system is then simulated twice.

    
Compute the state feedback gains to regulate an inverted pendulum about the upright position:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
Displacements and of the cart and the pendulum from an initial cart position of :
In[3]:=
Click for copyable input
Out[3]=
The displacements are also regulated when disturbances are present:
In[4]:=
Click for copyable input
Out[4]=