CARE
This function computes the stabilizing solution matrix X for the continuous-time algebraic Riccati equation used in linear quadratic regulator design and continuous-time state estimation.
A^T X + X A - X B R^{-1} B^T X + Q = 0
The matrix X balances state penalty terms from Q against control effort penalties from R. For stabilizable systems with appropriate weighting matrices, the stabilizing solution defines the optimal quadratic cost-to-go and is a standard building block for LQR feedback gains.
Excel Usage
=CARE(A, B, Q, R)
A(list[list], required): State dynamics matrix A.B(list[list], required): Input matrix B.Q(list[list], required): State weighting matrix Q.R(list[list], optional, default: null): Input weighting matrix R.
Returns (list[list]): The solution matrix X.
Example 1: Simple Riccati solution
Inputs:
| A | B | Q | R | ||
|---|---|---|---|---|---|
| 0 | 1 | 0 | 1 | 0 | 1 |
| 0 | 0 | 1 | 0 | 1 |
Excel formula:
=CARE({0,1;0,0}, {0;1}, {1,0;0,1}, {1})
Expected output:
| Result | |
|---|---|
| 1.73205 | 1 |
| 1 | 1.73205 |
Example 2: Scalar continuous Riccati equation
Inputs:
| A | B | Q | R |
|---|---|---|---|
| -1 | 1 | 2 | 1 |
Excel formula:
=CARE({-1}, {1}, {2}, {1})
Expected output:
0.732051
Example 3: Omitted R uses identity weighting
Inputs:
| A | B | Q | ||
|---|---|---|---|---|
| 0 | 1 | 0 | 2 | 0 |
| 0 | 0 | 1 | 0 | 1 |
Excel formula:
=CARE({0,1;0,0}, {0;1}, {2,0;0,1})
Expected output:
| Result | |
|---|---|
| 2.7671 | 1.41421 |
| 1.41421 | 1.95664 |
Example 4: Diagonal stable system with anisotropic state cost
Inputs:
| A | B | Q | R | ||||
|---|---|---|---|---|---|---|---|
| -1 | 0 | 1 | 0 | 3 | 0 | 2 | 0 |
| 0 | -2 | 0 | 1 | 0 | 1 | 0 | 4 |
Excel formula:
=CARE({-1,0;0,-2}, {1,0;0,1}, {3,0;0,1}, {2,0;0,4})
Expected output:
| Result | |
|---|---|
| 1.16228 | 0 |
| 0 | 0.246211 |
Python Code
Show Code
import control as ct
import numpy as np
def care(A, B, Q, R=None):
"""
Solve the continuous-time algebraic Riccati equation.
See: https://python-control.readthedocs.io/en/latest/generated/control.care.html
This example function is provided as-is without any representation of accuracy.
Args:
A (list[list]): State dynamics matrix A.
B (list[list]): Input matrix B.
Q (list[list]): State weighting matrix Q.
R (list[list], optional): Input weighting matrix R. 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.care(a_np, b_np, q_np, r_np)
return X.tolist()
except Exception as e:
return f"Error: {str(e)}"Online Calculator
State dynamics matrix A.
Input matrix B.
State weighting matrix Q.
Input weighting matrix R.