home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / r / rlab / CTB / lyap < prev    next >
Encoding:
Text File  |  1995-11-15  |  1.2 KB  |  64 lines

  1. //-------------------------------------------------------------------//
  2. // lyap.r:
  3. //
  4. // Syntax:    lyap ( A , B , C )
  5. //
  6. // Description:
  7. //
  8. // lyap solves the general form of the Lyapunov (Sylvester) equation:
  9. //
  10. //    A*X + X*B = -C
  11. //
  12. // by calling lyap as X=lyap(A,B,C)
  13. //
  14. // To solve the special form of the Lyapunov equation:
  15. //
  16. //    A*X + X*A' = -C
  17. //
  18. // call lyap as X=lyap(A,C)
  19. //
  20. // See Also: schur, sylv
  21. //-------------------------------------------------------------------//
  22.  
  23. static (lyap_sol)
  24.  
  25. lyap = function ( A, B, C )
  26. {
  27.    if (!exist (C))
  28.    {
  29.       if ((A.nr != A.nc) || (B.nr != B.nc)) {
  30.         error ("LYAP: Dimensions do not agree.");
  31.       }
  32.       return lyap_sol (A, A', B);
  33.    else
  34.       if ((A.nr != A.nc) || (B.nr != B.nc) || (C.nr != A.nr) || (C.nc != B.nr)) {
  35.        error ("LYAP: Dimensions do not agree.");
  36.       }
  37.       return lyap_sol (A, B, C);
  38.    }
  39. };
  40.  
  41. //-------------------------------------------------------------------//
  42.  
  43. lyap_sol = function ( A , B , C )
  44. {
  45.   local (sa, sb, tc, X)
  46.  
  47. // Schur decomposition on A and B
  48.  
  49.    sa = schur (A);
  50.    sb = schur (B);
  51.  
  52. // transform C
  53.  
  54.    tc = sa.z' * C * sb.z;
  55.  
  56. // Use Slyvester's Eqn. Solver to solve problem
  57.  
  58.    X = sylv(sa.t, sb.t, tc);
  59.  
  60. // Undo the transformation
  61.  
  62.    return sa.z * X * sb.z';
  63. };
  64.