control//Riccati equation
The Riccati equation is a quadratic matrix equation whose symmetric solution \(P\) summarizes, for a linear system with a quadratic cost, everything an optimal controller or an optimal estimator needs to know; it is what a control library solves when you ask it for an LQR gain or a steady-state Kalman filter. Nobody solves it by hand: `control.lqr` or `scipy.linalg.solve_continuous_are` return it in milliseconds, offline, and the controller that flies only multiplies by the gain it produced.
The Riccati equation is a quadratic matrix equation whose symmetric solution PPP summarizes, for a linear system with a quadratic cost, everything an optimal controller or an optimal estimator needs to know; it is what a control library solves when you ask it for an LQR gain or a steady-state Kalman filter. Nobody solves it by hand: control.lqr or scipy.linalg.solve_continuous_are return it in milliseconds, offline, and the controller that flies only multiplies by the gain it produced.
In the regulator problem the continuous algebraic Riccati equation reads
ATP+PA−PBR−1BTP+Q=0,A^{\mathsf T}P+PA-PBR^{-1}B^{\mathsf T}P+Q=0,ATP+PA−PBR−1BTP+Q=0,
with AAA and BBB the linearized plant, QQQ the price of state error and RRR the price of effort. The solution has a meaning worth keeping in mind: xTPxx^{\mathsf T}PxxTPx is the minimum cost still to pay from state xxx if you act optimally from now on, and the optimal gain follows directly as K=R−1BTPK=R^{-1}B^{\mathsf T}PK=R−1BTP. The quadratic term PBR−1BTPPBR^{-1}B^{\mathsf T}PPBR−1BTP is what actuation removes from that cost; QQQ is what the error keeps adding; ATP+PAA^{\mathsf T}P+PAATP+PA is how the plant's own motion carries cost along.
One equation, read in two directions.
Transpose AAA, put CTC^{\mathsf T}CT where BBB was, and the same equation becomes the one that propagates the Kalman filter's error covariance. In the regulator it runs backward in time and accumulates cost to go; in the filter it runs forward and accumulates uncertainty. That symmetry is the estimation-control duality.
The time-varying form is a differential (or, sampled, a difference) equation in P(t)P(t)P(t); the algebraic form is its steady state, reached when the horizon is long or the filter has run long enough. A drone autopilot uses the steady-state gain because its hover model does not change; a filter started with a large initial covariance runs the time-varying recursion until it settles (steady-state Kalman filter).
The microcontroller uses the discrete version (ct.dlqr), computed for the sampling period of the loop. A gain from the continuous equation applied at a slow rate is a different controller.
A stabilizing solution exists when the plant is stabilizable and the costed states are detectable, which is controllability and observability in their weakest useful form. A near-degenerate pair gives a solution with huge entries: the gain asks for actuation the motors do not have.
The same matrix reappears as the terminal cost of an MPC, where it stands in for everything beyond the horizon, and as the value function of the linear-quadratic case of the Bellman equation.