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:
Displacements and of the cart and the pendulum from an initial cart position of :
The displacements are also regulated when disturbances are present: