Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 34

Solving the Algebraic Riccati Equation for LQR

Recommended resources

Hello! Welcome to the next lesson in your journey into multivariable control.

In our last two lessons, we've built the foundation for LQR control. First, we formulated the optimization problem with its quadratic cost function. Then, we explored the art of tuning the weighting matrices, and , to shape the system's response. We've been treating commands like MATLAB's lqr as a "black box" that magically produces the optimal gain matrix .

Today, we're going to open that black box. This lesson reveals the mathematical engine at the heart of LQR: the Algebraic Riccati Equation (ARE). You will learn how solving this equation provides the key to directly calculating the optimal state feedback gain, . Understanding this process will demystify how LQR controllers are synthesized and give you a deeper appreciation for the tools you're using.

1. The LQR Solution: A Direct Formula for K

Let's start with the answer. For the infinite-horizon LQR problem we've defined, with the cost function:

and system dynamics , some very clever mathematicians proved that the control law that minimizes is a simple state feedback controller:

The revolutionary part is that the optimal gain matrix, , can be calculated directly using a formula. It's not found by trial-and-error, but through a deterministic computation. The formula is:

This is a powerful result. It tells us that if we can find this special matrix, , we can immediately compute our optimal controller gain. So, the entire problem now boils down to one question: What is ?


2. The Algebraic Riccati Equation (ARE)

The matrix is the unique, symmetric, positive-definite solution to the Continuous-time Algebraic Riccati Equation (CARE), often just called the ARE. For a system defined by matrices , the ARE is:

Let's break this down:

  • This is a matrix equation. The unknown we are solving for is the entire matrix , where is the number of states.
  • It's non-linear. Notice the term, which is quadratic in . This is why it's more complex than the linear systems you're used to.
  • It's algebraic because it doesn't involve any derivatives of .

The workflow for designing an LQR controller is therefore not about guessing , but about solving this equation for and then using to find .

To get a bit of intuition about where this equation originates, the following video provides a nice conceptual derivation without getting lost in the full mathematical proof.

Why the Riccati Equation Is important for LQR Control

To understand where this equation comes from without delving into a deep mathematical proof, this video from the MATLAB channel offers an excellent conceptual derivation. It uses a technique known as 'completing the square' to cleverly rearrange the cost function.

Watch from 7:12 to 11:20. Focus on the main steps: 1) introducing the unknown matrix P (which we are calling S), 2) expanding the cost function, and 3) rearranging it into a form where two parts can be driven to zero. Don't worry about memorizing the matrix algebra; just follow the logic of how the final two key equations emerge.

As the video explains, by manipulating the cost function, we arrive at two conditions for optimality:

  1. The matrix must satisfy the ARE, which makes one part of the cost function zero.
  2. The control input must be chosen to make the other part of the cost function zero, which leads directly to the state feedback law , where is defined using .

3. Solving the ARE: A Step-by-Step Procedure

Since the ARE is a quadratic matrix equation, solving it isn't as simple as taking an inverse. It can have multiple solutions. However, for a controllable system, there is only one solution for that is positive-definite and results in a stable closed-loop system . This is the "stabilizing solution" we are looking for.

The following video provides an outstanding walkthrough of the practical procedure for solving the ARE and finding the correct gain .

Introduction to Linear Quadratic Regulator (LQR) Control

Now that we know what the Algebraic Riccati Equation is, let's see how it's solved in practice. This video from Christopher Lum walks through a clear, five-step procedure for finding the optimal gain K, starting from the system model and the ARE.

Watch from 41:30 to 1:00:49. The video uses a simple mass-damper system as an example. Pay close attention to the procedure demonstrated in Mathematica: 1. Defining A, B, Q, R. 2. Setting up and solving the ARE for S, which yields multiple solutions. 3. Calculating the gain K for each solution. 4. Checking the eigenvalues (poles) of the closed-loop system for stability. 5. Selecting the single K that stabilizes the system. This process reveals exactly what happens inside a command like lqr.

To summarize the procedure shown in the video:

  1. Define System and Costs: Start with your system matrices and , and your chosen weighting matrices and .
  2. Solve the ARE for S: Solve the equation . This will generally yield multiple solutions for the matrix .
  3. Compute Potential Gains (K): For each solution , calculate a corresponding gain matrix .
  4. Check Stability: For each gain , form the closed-loop system matrix . Calculate its eigenvalues (poles).
  5. Select the Stabilizing Gain: The correct, optimal gain is the one that results in a stable closed-loop system, meaning all eigenvalues of have negative real parts. There will be only one such gain.

4. From Manual Calculation to Software Tools

As you saw in the video, solving the ARE manually, even for a simple 2-state system, is quite tedious. This is where software tools become indispensable. A single command can execute that entire five-step process.

Let's look at the official MATLAB documentation for the lqr function to confirm this.

lqr - Linear-Quadratic Regulator (LQR) design - MATLAB

The MATLAB lqr command automates the entire process of solving the ARE and finding the stabilizing gain. This documentation page shows exactly what the function does.

First, review the 'Syntax' and 'Description' sections to see that lqr can return not just the gain K, but also the Riccati solution S and the closed-loop poles P. Then, scroll down to the 'Algorithms' section to see the exact continuous-time ARE that MATLAB solves. Finally, examine the example output under '[K,S,P] = lqr(sys,Q,R)' to see how K and S are returned for a sample system.

The syntax [K,S,P] = lqr(A,B,Q,R) perfectly maps to the procedure we just learned. The function:

  • Solves the ARE for the stabilizing solution S.
  • Calculates K using S.
  • Returns the resulting closed-loop poles P for you to inspect.

This automates the laborious and error-prone parts of the design, letting you focus on the high-level task of choosing and .

Test your understanding!

Consider a simple system with:

Solving the ARE, , gives two symmetric solutions for :

Which one is the correct stabilizing solution? To find out:

  1. Calculate the gain from and from .
  2. Determine the eigenvalues of the closed-loop system and .
  3. Identify the optimal gain .
Show answer
  1. Calculate Gains: The formula is .

    • For :
    • For :
  2. Check Stability (Eigenvalues):

    • For : . The eigenvalues are approximately . Both have negative real parts, so this system is stable.
    • For : . The eigenvalues are approximately . Both have positive real parts, so this system is unstable.
  3. Identify Optimal Gain:
    The stabilizing solution is . Therefore, the optimal LQR gain is .


Conclusion

You have now completed the core theory of LQR design. You've seen that the "magic" of the lqr command is rooted in solid mathematics.

Key Takeaways:

  • The optimal LQR control law is a state feedback law .
  • The gain is computed from a matrix using the formula .
  • The matrix is the unique stabilizing solution to the Algebraic Riccati Equation (ARE): .
  • Software tools automate the process of solving the ARE and selecting the correct solution, but understanding this underlying process is key to being an effective control designer.

Preview of the Next Lesson:
Our LQR controller is excellent at regulation—that is, driving the system's states to zero and keeping them there. However, for many applications, including your rotary inverted pendulum, you'll want the system to follow a non-zero command (e.g., move the cart to a new position). In the next lesson, we will build on our LQR controller to add reference tracking, enabling your system to follow setpoints and trajectories.