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

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