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

  1. //-----------------------------------------------------------------
  2. //
  3. // dlyap
  4. //
  5. // Syntax: x=dlyap(Ad,Cd)
  6. //
  7. // This routine solves the Discrete Lyapunov Equation. Calling
  8. // the routine as,
  9. //
  10. //    X=dlyap(A,C)
  11. //
  12. // returns X, which is the solution to the following
  13. // discrete Lyapunov Equation.
  14. //
  15. //     A*X*A' + C = X
  16. //
  17. // Copyright (C), by Jeffrey B. Layton, 1994
  18. // Version JBL 940918
  19. //-----------------------------------------------------------------
  20.  
  21. rfile lyap
  22.  
  23. dlyap = function(Ad,Cd)
  24. {
  25.    local(nargs,n,Ac,Cc,X)
  26.  
  27. // Count number of input arguments
  28.    nargs=0;
  29.    if (exist(Ad)) {nargs=nargs+1;}
  30.    if (exist(Cd)) {nargs=nargs+1;}
  31.  
  32.    if (nargs < 2) {
  33.        error("DLYAP: Wrong number of input arguments.");
  34.    }
  35.  
  36. // Define dimensions
  37.    n=Ad.nr;
  38.  
  39. // Convert discrete to continuous
  40.    Ac=solve((Ad+eye(n,n)),(Ad-eye(n,n)));
  41.    Cc=((eye(n,n)-Ad)*Cd*(eye(n,n)-Ad'))/2.0;
  42.  
  43. // Call continuous lyapunov solver to solve problem.
  44.    X=lyap(Ac,Cc);
  45.  
  46.    return X
  47. };
  48.