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

  1. function [K,P,Perr] = dlqrc(A,B,QRN,aretype)
  2. %
  3. % [K,P,PERR] = DLQRC(A,B,QRN,ARETYPE) solves the discrete Riccati equation
  4. %     and produces the discrete optimal LQR feedback gain K such that the 
  5. %     feedback law u = -Kx minimizes the cost function in time interval [i,n]
  6. %             n-1
  7. %  J(i) = 1/2 SUM { [x(k)' u(k)'] | Q  N | |x(k)| }; ( QRN := |Q  N| )
  8. %             k=i                 | N' R | |u(k)|    (        |N' R| )
  9. %              
  10. %     subject to the constraint equation: x(k+1) = A(k)x(k) + B(k)u(k)
  11. %     Also returned is P, the steady-state solution to the discrete ARE:
  12. %                           -1
  13. %        0 = A'PA - P - A'PB(R+B'PB)  B'P'A + Q
  14. %
  15. %     In addition, it will calculate the residual of the ARE. If the 
  16. %     problem is ill-posed such that the residual is large or there 
  17. %     exists closed loop poles with unity magnitute, a warning message 
  18. %     will be displyed.
  19. %
  20. %     aretype = 'eigen' --- solve Riccati via eigenstructure (default)
  21. %     aretype = 'Schur' --- solve Riccati via Schur method.
  22. %
  23.  
  24. % R. Y. Chiang & M. G. Safonov 8/85
  25. % Copyright (c) 1988 by the MathWorks, Inc.
  26. % All Rights Reserved.
  27. % ------------------------------------------------------------------------
  28. if nargin == 3
  29.    aretype = 'eigen';
  30. end
  31. %
  32. [n,n] = size(A);
  33. [Q,N,NT,R] = sys2ss(QRN,n);
  34. Q = Q - N/R*NT;
  35. A = A - B/R*NT;
  36. [P1,P2,Perr,wellposed,P] = daresolv(A,B,Q,R,aretype);
  37. K = (R+B'*P*B)\B'*P*A + R\NT;
  38. %
  39. % ------ End of DLQRC.M ---- RYC/MGS %
  40.