Discrete Algebraic Riccati Equation (DARE)

March 21, 2026 · View on GitHub

Overview & Motivation

The Discrete Algebraic Riccati Equation arises whenever you need to find an optimal trade-off between state regulation and control effort in a discrete-time linear system. It is the mathematical core of two fundamental algorithms:

  1. LQR control — computing the optimal state-feedback gain.
  2. Steady-state Kalman filtering — computing the optimal estimator gain.

The DARE finds a symmetric positive semi-definite matrix PP that encodes the cost-to-go from any state. Once PP is known, the optimal gain is a simple closed-form expression. This library solves the DARE via fixed-point iteration — simple to implement, numerically transparent, and well-suited to the small state dimensions typical in embedded control.

Mathematical Theory

The Equation

P=ATPAATPB(R+BTPB)1BTPA+QP = A^T P A - A^T P B \left(R + B^T P B\right)^{-1} B^T P A + Q

where:

  • ARn×nA \in \mathbb{R}^{n \times n} — state transition matrix
  • BRn×mB \in \mathbb{R}^{n \times m} — input matrix
  • QRn×nQ \in \mathbb{R}^{n \times n} — state weighting matrix (Q0Q \succeq 0)
  • RRm×mR \in \mathbb{R}^{m \times m} — input weighting matrix (R0R \succ 0)
  • PRn×nP \in \mathbb{R}^{n \times n} — the unknown (P0P \succeq 0)

Iterative Solution

Starting from P0=QP_0 = Q:

  1. S=R+BTPkBS = R + B^T P_k B
  2. Solve SKpart=BTPkAS \cdot K_{\text{part}} = B^T P_k A (via Gaussian Elimination)
  3. Pk+1=ATPkAATPkBKpart+QP_{k+1} = A^T P_k A - A^T P_k B \cdot K_{\text{part}} + Q
  4. If Pk+1Pk<ε\|P_{k+1} - P_k\| < \varepsilon, converged.

Existence and Convergence

A unique stabilizing solution exists when:

  • (A,B)(A, B) is stabilizable (unstable modes are controllable).
  • (A,C)(A, C) is detectable (where Q=CTCQ = C^T C).

Under these conditions, the iteration converges monotonically: P0P1PP_0 \preceq P_1 \preceq \cdots \preceq P^*.

Optimal Gain

K=(R+BTPB)1BTPAK = \left(R + B^T P B\right)^{-1} B^T P A

Complexity Analysis

PhaseTimeSpaceNotes
Per iterationO(n3+n2m+m3)O(n^3 + n^2 m + m^3)O(n2)O(n^2)Matrix multiplications + one m×mm \times m linear solve
Total solverO(I(n3+m3))O(I(n^3 + m^3))O(n2)O(n^2)II iterations (typically 10–30)

Why O(n3)O(n^3): Each iteration involves n×nn \times n matrix products (ATPAA^T P A) and an m×mm \times m linear solve (for S1S^{-1}). When mnm \ll n, the matrix products dominate.

Step-by-Step Walkthrough

System: n=2n=2, m=1m=1, A=[10.101]A = \begin{bmatrix}1 & 0.1\\0 & 1\end{bmatrix}, B=[0.0050.1]B = \begin{bmatrix}0.005\\0.1\end{bmatrix}, Q=I2Q = I_2, R=[1]R = [1].

Iteration 0: P0=Q=I2P_0 = Q = I_2

  1. S=R+BTP0B=1+[0.005  0.1][0.0050.1]=1.010025S = R + B^T P_0 B = 1 + [0.005\; 0.1]\begin{bmatrix}0.005\\0.1\end{bmatrix} = 1.010025
  2. BTP0A=[0.005  0.1][10.101]=[0.005,  0.1005]B^T P_0 A = [0.005\; 0.1]\begin{bmatrix}1 & 0.1\\0 & 1\end{bmatrix} = [0.005,\; 0.1005]
  3. Kpart=[0.005,  0.1005]/1.010025=[0.00495,  0.0995]K_{\text{part}} = [0.005,\; 0.1005] / 1.010025 = [0.00495,\; 0.0995]
  4. ATP0A=[100.11][10.101]=[10.10.11.01]A^T P_0 A = \begin{bmatrix}1 & 0\\0.1 & 1\end{bmatrix}\begin{bmatrix}1 & 0.1\\0 & 1\end{bmatrix} = \begin{bmatrix}1 & 0.1\\0.1 & 1.01\end{bmatrix}
  5. Correction term [0.00002480.0004980.0004980.00999]\approx \begin{bmatrix}0.0000248 & 0.000498\\0.000498 & 0.00999\end{bmatrix}
  6. P1[2.00.09950.09952.000]P_1 \approx \begin{bmatrix}2.0 & 0.0995\\0.0995 & 2.000\end{bmatrix}

Iterations 1–20: PP grows monotonically until convergence. For this Q/RQ/R ratio, PP^* stabilizes in ~15 iterations.

Pitfalls & Edge Cases

  • Non-stabilizable system. The iteration diverges if (A,B)(A, B) is not stabilizable. Check the controllability matrix rank before calling the solver.
  • RR must be positive definite. The linear solve SKpart=S \cdot K_{\text{part}} = \ldots fails if SS is singular, which happens when RR has zero eigenvalues.
  • Slow convergence. Systems with eigenvalues near the unit circle converge slowly. Increase the maximum iteration bound if needed.
  • Fixed-point overflow. The matrix products can easily exceed Q15/Q31 ranges. Use floating-point for the solve; deploy the resulting KK as a fixed-point constant.
  • Tolerance type-awareness. The convergence test uses math::Tolerance<T>(), which adapts to both float and fixed-point types.

Variants & Generalizations

VariantKey Difference
Continuous ARE (CARE)For continuous-time systems; different matrix equation
Newton's method for DAREQuadratic convergence but requires solving a Sylvester equation per iteration
Schur methodEigendecomposition-based; finds the solution in one pass but requires O(n3)O(n^3) eigenvalue computation
Doubling algorithmO(logI)O(\log I) convergence via matrix sign function; useful for large systems

Applications

  • LQR control — The LQR controller derives its gain from the DARE solution.
  • Kalman filter steady-state gain — The dual DARE (swapping AATA \to A^T, BHTB \to H^T, QQprocessQ \to Q_{\text{process}}, RRmeasurementR \to R_{\text{measurement}}) gives the steady-state Kalman gain.
  • HH_\infty control — Robust controller design involves coupled Riccati equations.
  • Model predictive control — The terminal cost matrix in MPC is often the DARE solution.

Connections to Other Algorithms

graph LR
    DARE["DARE Solver"]
    GE["Gaussian Elimination"]
    LQR["LQR Controller"]
    KF["Kalman Filter"]
    GE --> DARE
    DARE --> LQR
    DARE --> KF
AlgorithmRelationship
Gaussian EliminationUsed at each iteration to solve the m×mm \times m linear sub-system
LQR ControllerDirect consumer — extracts optimal gain KK from the DARE solution matrix PP
Kalman FilterDual problem — the steady-state Kalman gain is computed by a transposed DARE

References & Further Reading

  • Lancaster, P. and Rodman, L., Algebraic Riccati Equations, Oxford University Press, 1995.
  • Anderson, B.D.O. and Moore, J.B., Optimal Control: Linear Quadratic Methods, Prentice Hall, 1990 — Chapter 4.
  • Laub, A.J., "A Schur method for solving algebraic Riccati equations", IEEE Transactions on Automatic Control, 24(6), 1979.