DARE
This function computes the stabilizing solution matrix X for the discrete-time algebraic Riccati equation used in optimal control and discrete-time filtering problems.
A^T X A - X - A^T X B (B^T X B + R)^{-1} B^T X A + Q = 0
The solution defines the quadratic cost-to-go for a discrete-time regulator and is used to derive optimal state feedback gains. When R is omitted, the underlying library uses an identity input weighting matrix.
Excel Usage
=DARE(A, B, Q, R)
A(list[list], required): Discrete state dynamics matrix A.B(list[list], required): Discrete input matrix B.Q(list[list], required): State weighting matrix Q.R(list[list], optional, default: null): Input weighting matrix R. If omitted, the identity matrix is used.
Returns (list[list]): The solution matrix X.
Example 1: Discrete Riccati solution
Inputs:
| A | B | Q | R | ||
|---|---|---|---|---|---|
| 1 | 1 | 0.5 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 | 1 |
Excel formula:
=DARE({1,1;0,1}, {0.5;1}, {1,0;0,1}, {1})
Expected output:
| Result | |
|---|---|
| 2.3671 | 1.11803 |
| 1.11803 | 2.58748 |
Example 2: Scalar discrete Riccati equation
Inputs:
| A | B | Q | R |
|---|---|---|---|
| 0.8 | 1 | 1 | 1 |
Excel formula:
=DARE({0.8}, {1}, {1}, {1})
Expected output:
1.36995
Example 3: Omitted R uses identity weighting in discrete time
Inputs:
| A | B | Q |
|---|---|---|
| 0.9 | 1 | 2 |
Excel formula:
=DARE({0.9}, {1}, {2})
Expected output:
2.584
Example 4: Two-state discrete regulator design
Inputs:
| A | B | Q | R | ||
|---|---|---|---|---|---|
| 1 | 0.1 | 0 | 1 | 0 | 0.5 |
| 0 | 0.9 | 1 | 0 | 2 |
Excel formula:
=DARE({1,0.1;0,0.9}, {0;1}, {1,0;0,2}, {0.5})
Expected output:
| Result | |
|---|---|
| 15.8497 | 1.74312 |
| 1.74312 | 2.53848 |
Python Code
Show Code
import control as ct
import numpy as np
def dare(A, B, Q, R=None):
"""
Solve the discrete-time algebraic Riccati equation.
See: https://python-control.readthedocs.io/en/latest/generated/control.dare.html
This example function is provided as-is without any representation of accuracy.
Args:
A (list[list]): Discrete state dynamics matrix A.
B (list[list]): Discrete input matrix B.
Q (list[list]): State weighting matrix Q.
R (list[list], optional): Input weighting matrix R. If omitted, the identity matrix is used. Default is None.
Returns:
list[list]: The solution matrix X.
"""
try:
def to_np(x):
if x is None:
return None
if not isinstance(x, list):
return np.array([[float(x)]])
if x and not isinstance(x[0], list):
x = [x]
return np.array([[float(v) if v is not None and str(v) != "" else 0.0 for v in row] for row in x])
a_np = to_np(A)
b_np = to_np(B)
q_np = to_np(Q)
r_np = to_np(R)
X, L, G = ct.dare(a_np, b_np, q_np, r_np)
return X.tolist()
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Discrete state dynamics matrix A.
Discrete input matrix B.
State weighting matrix Q.
Input weighting matrix R. If omitted, the identity matrix is used.