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

  1. //----------------------------------------------------------------------------
  2. //
  3. // lqry
  4. //
  5. // Syntax: G=lqry(A,B,Q,R,CT)
  6. //
  7. // This routine computes the Linear Quadratic Design for Continuous Systems
  8. // with weighting on the outputs. It calculates the optimal feedback gain
  9. // matrix K such that the feedbakc law u = -Kx minimizes the following
  10. // cost function:
  11. //
  12. //           Inf
  13. //     J = Integral ( y'Qy + u'Ru ) dt
  14. //            0
  15. //
  16. // subject to the constraint
  17. //
  18. //   .
  19. //   x = Ax + Bu
  20. //   y = Cx + Du
  21. //
  22. // Note: Three matrices are returned in a list.
  23. //
  24. //       G.k = Optimal Feedback Gain matrix
  25. //       G.s = Steady-State Solution to the Algebraic Riccatti Eqn.
  26. //       G.e = Closed Loop eigenvalues
  27. //
  28. //
  29. // Copyright (C), by Jeffrey B. Layton, 1994
  30. // Version JBL 940919
  31. //----------------------------------------------------------------------------
  32.  
  33. rfile lqr
  34.  
  35. lqry = function(a,b,c,d,q,r)
  36. {
  37.    local(nargs,t)
  38.  
  39. // Count number of input arguments
  40.    nargs=0;
  41.    if (exist(a)) {nargs=nargs+1;}
  42.    if (exist(b)) {nargs=nargs+1;}
  43.    if (exist(c)) {nargs=nargs+1;}
  44.    if (exist(d)) {nargs=nargs+1;}
  45.    if (exist(q)) {nargs=nargs+1;}
  46.    if (exist(r)) {nargs=nargs+1;}
  47.  
  48.    if (nargs != 6 ) {
  49.        error("LQRY: Wrong number of input arguments.");
  50.    }
  51.  
  52.    t=lqr(a,b, c'*q*c, r+d'*q*d, c'*q*d);
  53.  
  54.    return << k=t.k; s=t.s; e=t.e >>
  55. };
  56.