Solution
Solving Lyapunov equations in Matlab is very easy. Both the continuous and discrete Lyapunov equation have a built-in function:
Extra note: if the links would not work, or you want a quick way to check the documentation of a Matlab function offline, every built-in Matlab function has a short help page reachable by help NameOfTheFunction
.
Furthermore the extended help page, as also visible on the web, with examples can also be retrieved offline by typing doc NameOfTheFunction
in the Matlab terminal.
Example
Given the following continuous Lyapunov equation:
A*X + X*transpose(A) + Q = 0
The solution in Matlab for a stable A
and positive definite Q
is given as:
X = lyap(A,Q)
In some cases the equation is slightly different:
A*X + X*B + C = 0
This equation calls the Sylvester equation and is again solvable with the built-in Lyapunov function of Matlab:
X = lyap(A,B,C)
The same analogue solution steps exist for the discrete case, where the Lyapunov and Sylvester equation look slightly different:
A*X*transpose(A) -X + Q = 0 -> X = dlyap(A,Q)
A*X*B - X + C = 0 -> X = dlyap(A,B,C)