Introduction to Linear Quadratic Regulator (LQR) Control

Christopher Lum
lum@uw.edu

This document accompanies the YouTube video at https://youtu.be/wEevt2a4SKI.

Solving the Algebraic Ricatti Equation

(*Step 1: Define A and B*)
A=(({{0, 1}, {0, -1/5}}));
B=(({{0}, {1}}));

(*Step 2:  Choose Q and R*)
Q=(({{1, 0}, {0, 1}}));
R={{1/100}};

(*Step 3:  Solve ARE*)

Recall that the Algebraic Ricatti Equation (ARE) is given as

	(A^T)S+S A-S B (R^(-1))(B^T) S+Q=0
	
We now solve this for S using the fact that S is a symmetric, n-by-n matrix.

(*Define S as a symmetric matrix of size n-by-n*)
S=(({{s11, s12}, {s12, s22}}));

(*Solve ARE*)
LHS=Transpose[A].S+S.A-S.B.Inverse[R].Transpose[B].S+Q//Simplify;
LHS//MatrixForm

temp=Solve[{LHS[[1,1]]==0,LHS[[1,2]]==0,LHS[[2,2]]==0},{s11,s12,s22}]

This yields 4 unique solutions.  We need to explore each solution to determine which one yields a stabilizing controller (all eigenvalues in the left half plane).

solution1=temp[[1]]
solution2=temp[[2]]
solution3=temp[[3]]
solution4=temp[[4]]

S1=S/.solution1;
S2=S/.solution2;
S3=S/.solution3;
S4=S/.solution4;

S1//N//MatrixForm
S2//N//MatrixForm
S3//N//MatrixForm
S4//N//MatrixForm

(*Step 4:  Compute K*)

K=(R^(-1))(B^T)S

K1=Inverse[R].Transpose[B].S1;
K2=Inverse[R].Transpose[B].S2;
K3=Inverse[R].Transpose[B].S3;
K4=Inverse[R].Transpose[B].S4;

K1//N//MatrixForm
K2//N//MatrixForm
K3//N//MatrixForm
K4//N//MatrixForm

(*Step 5:  Find solution that yields stable system*)

λ1=Eigenvalues[A-B.K1];
λ2=Eigenvalues[A-B.K2];
λ3=Eigenvalues[A-B.K3];
λ4=Eigenvalues[A-B.K4];

λ1//N
λ2//N
λ3//N
λ4//N

We see that only the 4th solution yields a stabilizing controller.

S4//MatrixForm//N
K4//N