This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org
Viv Python

Notebooks · lib/lyap

The Lyapunov equation, by Bartels and Stewart

The continuous-time Lyapunov equation

A^T X + X A + C = 0

is linear in X, so in principle it is n^2 equations in n^2 unknowns and you could hand it to a linear solver. Doing that costs n^6 and throws away every bit of structure the problem has. Bartels and Stewart's method, which is what SLICOT's SB03MD does, costs n^3.

The trick is to put A into real Schur form first, A = U T U^T. Substituting X = U Y U^T and multiplying through by U^T and U turns the equation into

T^T Y + Y T + U^T C U = 0

with T quasi-triangular. Now the entries of Y come out by back-substitution: the block in row i and column j depends only on blocks above it and to its left, so sweeping in order leaves one small equation per block, of size at most 2 by 2 on each side, which is at most four unknowns. Then X = U Y U^T.

What it is for: the two Gramians. A Wc + Wc A^T + B B^T = 0 gives the states the input can reach, A^T Wo + Wo A + C^T C = 0 gives the states the output can see, and between them they give the H2 norm of the system, its response energy to an impulse. Balanced truncation — deciding which states of a large model can be thrown away — is the eigenvalue problem of their product.

The H2 norm has two expressions, one through each Gramian. They are computed separately here and the test holds them to each other, which catches an error in either one.

Used with import lyap.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 37–356