home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
- // lyap.r:
- //
- // Syntax: lyap ( A , B , C )
- //
- // Description:
- //
- // lyap solves the general form of the Lyapunov (Sylvester) equation:
- //
- // A*X + X*B = -C
- //
- // by calling lyap as X=lyap(A,B,C)
- //
- // To solve the special form of the Lyapunov equation:
- //
- // A*X + X*A' = -C
- //
- // call lyap as X=lyap(A,C)
- //
- // See Also: schur, sylv
- //-------------------------------------------------------------------//
-
- static (lyap_sol)
-
- lyap = function ( A, B, C )
- {
- if (!exist (C))
- {
- if ((A.nr != A.nc) || (B.nr != B.nc)) {
- error ("LYAP: Dimensions do not agree.");
- }
- return lyap_sol (A, A', B);
- else
- if ((A.nr != A.nc) || (B.nr != B.nc) || (C.nr != A.nr) || (C.nc != B.nr)) {
- error ("LYAP: Dimensions do not agree.");
- }
- return lyap_sol (A, B, C);
- }
- };
-
- //-------------------------------------------------------------------//
-
- lyap_sol = function ( A , B , C )
- {
- local (sa, sb, tc, X)
-
- // Schur decomposition on A and B
-
- sa = schur (A);
- sb = schur (B);
-
- // transform C
-
- tc = sa.z' * C * sb.z;
-
- // Use Slyvester's Eqn. Solver to solve problem
-
- X = sylv(sa.t, sb.t, tc);
-
- // Undo the transformation
-
- return sa.z * X * sb.z';
- };
-