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

  1. //----------------------------------------------------------------------------
  2. //
  3. // glqry
  4. //
  5. // Syntax: G=glqry(A,DA,B,DA,C,DC,D,DD,Q,DQ,R,DR)
  6. //
  7. // This routine computes the gradient of the Linear Quadratic Design with
  8. // respect to a scalar parameter 'p' for continuous systems with weightings
  9. // on the outputs. It compute the gradient of the feedback matrix K for the
  10. // feedback law,
  11. //
  12. //   u = -Kx
  13. //
  14. // with respect to 'p'. The system is described by,
  15. //   .
  16. //   x = Ax + Bu
  17. //   y = Cx + Du
  18. //
  19. // Note: Two matrices are returned in a list.
  20. //
  21. //       G.dk = Optimal Feedback Gain matrix
  22. //       G.ds = Steady-State Solution to the Algebraic Riccatti Eqn.
  23. //
  24. // Copyright (C), by Jeffrey B. Layton, 1994
  25. // Version JBL 940918
  26. //----------------------------------------------------------------------------
  27.  
  28. rfile glqr
  29.  
  30. glqry = function(a,da,b,db,c,dc,d,dd,q,dq,r,dr)
  31. {
  32.    local(nargs,r,dqlocal,drlocal,dctlocal)
  33.  
  34. // Count number of input arguments
  35.    nargs=0;
  36.    if (exist(a)) {nargs=nargs+1;}
  37.    if (exist(da)) {nargs=nargs+1;}
  38.    if (exist(b)) {nargs=nargs+1;}
  39.    if (exist(db)) {nargs=nargs+1;}
  40.    if (exist(c)) {nargs=nargs+1;}
  41.    if (exist(dc)) {nargs=nargs+1;}
  42.    if (exist(d)) {nargs=nargs+1;}
  43.    if (exist(dd)) {nargs=nargs+1;}
  44.    if (exist(q)) {nargs=nargs+1;}
  45.    if (exist(dq)) {nargs=nargs+1;}
  46.    if (exist(r)) {nargs=nargs+1;}
  47.    if (exist(dr)) {nargs=nargs+1;}
  48.  
  49.    if (nargs != 12) {
  50.        error("DLQRY: Wrong number of input arguments.");
  51.    }
  52.  
  53. // Begin: use glqr to solve problem
  54.    dqlocal=dc'*q*c + c'*dq*c + c'*q*dc;
  55.    drlocal=dr+dd'*q*d + d'*dq*d + d'*q*dd;
  56.    dctlocal=dc'*q*d + c'*dq*d + c'*q*dd;
  57.  
  58.    r=glqr(a,da,b,db,c'*q*c,dqlocal,r+d'*q*d,drlocal,c'*q*d,dctlocal);
  59.  
  60.    return << k=r.dk; s=r.dp >>
  61. };
  62.