home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 10.ddi / CONTROL.DI$ / LQR2.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.0 KB  |  72 lines

  1. function [k,p] = lqr2(a,b,q,r,s)
  2. %LQR2    Linear-quadratic regulator design for continuous-time systems.
  3. %    [K,S] = LQR2(A,B,Q,R)  calculates the optimal feedback gain matrix
  4. %    K such that the feedback law  u = -Kx  minimizes the cost function
  5. %
  6. %          J = Integral {x'Qx + u'Ru} dt
  7. %                                          .
  8. %    subject to the constraint equation:   x = Ax + Bu 
  9. %       
  10. %    Also returned is S, the steady-state solution to the associated 
  11. %    algebraic Riccati equation:
  12. %                              -1
  13. %            0 = SA + A'S - SBR  B'S + Q
  14. %
  15. %    [K,S] = LQR2(A,B,Q,R,N) includes the cross-term 2x'Nu that 
  16. %       relates u to x in the cost functional. 
  17. %
  18. %    The controller can be formed with REG.
  19. %
  20. %    LQR2 uses the SCHUR algorithm of [1] and is more numerically
  21. %    reliable than LQR, which uses eigenvector decomposition.
  22. %
  23. %    See also: ARE, LQR, and LQE2.
  24.  
  25. %    Copyright (c) 1986-93 by The MathWorks, Inc.
  26.  
  27. %  written-
  28. %       11 May 87  M. Wette, ECE Dep't., Univ. of California,
  29. %                            Santa Barbara, CA  93106, (805) 961-3616
  30. %                  e-mail:   mwette%gauss@hub.ucsb.edu
  31. %                            laub%lanczos@hbu.ucsb.edu
  32. %  revised-
  33. %       27 Aug 87  JNL
  34. %  revised-
  35. %       16 Mar 88  Wette & Laub
  36. %                  (changed notation and edited documentation)
  37.  
  38. % References:
  39. %  [1] A.J. Laub, "A Schur Method for Solving Algebraic Riccati
  40. %  Equations", IEEE Transactions on Automatic Control, vol. AC-24,
  41. %  1979, pp. 913-921.
  42.  
  43. % Convert data for linear-quadratic regulator problem to data for
  44. % the algebraic Riccati equation. 
  45. %    F = A - B*inv(R)*S'
  46. %    G = B*inv(R)*B'
  47. %    H = Q - S*inv(R)*S'
  48. % R must be symmetric positive definite.
  49.  
  50. error(nargchk(4,5,nargin));
  51. error(abcdchk(a,b));
  52.  
  53. [n,m] = size(b);
  54. ri = inv(r);
  55. rb = ri*b';
  56. g = b*rb;
  57. if (nargin > 4),
  58.     rs = ri*s';
  59.     f = a - b*rs;
  60.     h = q - s*rs;
  61. else;
  62.     f = a;
  63.     h = q;
  64.     rs = zeros(m,n);
  65. end;
  66.  
  67. % Solve ARE:
  68. p = are(f,g,h);
  69.  
  70. % Find gains:
  71. k = rs + rb*p;
  72.