Before modeling the control system in Simulink, I advise that you first understand the underlying mathematical design concepts, as the lqr() function is executed in MATLAB. I assume you will refer to textbooks to comprehend how the LQR algorithm calculates the control gain matrix
by solving the Riccati differential equation. Thus, I won't elaborate further on that topic. Many students linearize the nonlinear system and straightforwardly apply the control gain matrix computed by the LQR algorithm. However, they are often unable to achieve zero steady-state error because they tend to unknowingly neglect the effects of state-dependent disturbance, which is the byproduct of the mathematical linearization.
Here is a simple example for the control design.
Step 1: Get the mathemtical model of the inverted pendulum (an unstable nonlinear system):
where u is the controller.
Step 2: Linearize the nonlinearity:
The equation for the linearization of the function
at
is given by
.
Step 3: Express the nonlinear system in the linearized form for conrol design purposes:
where
is the state-dependent disturbance. If we design the controller as
by introducing an auxiliary control variable μ, the linearized system becomes or in the state-space representation
.where
is a state-dependent state matrix whose values change based on the system's current state, particularly
.
Step 4: Obtain the feedback control gain matrix K using the LQR algorithm:
function dx = linearInvertedPendulum(t, x)
Step 5: Solve using ode45 and plot the result:
[t, x] = ode45(@linearInvertedPendulum, [0 10], [1, 0]);
title('Pendulum''s Angle, $\theta$', 'interpreter', 'latex')