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

  1. function [p1,p2,lamp,perr,wellposed,p] = daresolv(A,B,Q,R,Type)
  2. %
  3. % [P1,P2,LAMP,PERR,WELLPOSED,P] = DARESOLV(A,B,Q,R,TYPE) computes the 
  4. % solution to the discrete algebraic Riccati equation
  5. %                                   -1
  6. %            A'PA - P - A'PB(R+B'PB)  B'PA + Q = 0
  7. %
  8. %   based on the "Type" one selects:
  9. %                Type = 'eigen' ---- Eigenstructure approach
  10. %
  11. %                Type = 'Schur' ---- Schur vector approach
  12. %
  13. %  Outputs:   P = P2/P1 riccati solution
  14. %             [P1;P2] stable eigenspace of hamiltonian matrix
  15. %             LAMP closed loop eigenvalues
  16. %             PERR residual error matrix 
  17. %             WELLPOSED = 'TRUE ' if hamiltonian has no imaginary-axis
  18. %                  eigenvalues, otherwise 'FALSE'
  19.  
  20. % R. Y. Chiang & M. G. Safonov 2/88
  21. % Copyright (c) 1988 by the MathWorks, Inc.
  22. % All Rights Reserved.
  23.  
  24. wellposed='TRUE ';  %initialize 
  25. if nargin == 3
  26.    Type = 'eigen';
  27. end
  28. %
  29. [n,n] = size(A);
  30. %
  31. % ------ If A is stable and Q is zero, p2 = zero(n), p1 = eye(n)
  32. %
  33. lamA = eig(A);
  34. ind = find(lamA>0);
  35. if (sum(ind) == 0) & (norm(q,'fro') == 0)
  36.    p2 = zeros(n); p1 = eye(n);
  37.    p = p2; perr = p2;
  38.    return
  39. end
  40. %   
  41. RR = B/R*B';
  42. ham = [A+RR/A'*Q -RR/A';-A'\Q inv(A')];
  43. %
  44. % ------ Eigenstructure approach:
  45. %
  46. if Type == 'eigen'
  47.    [v,d] = reig(ham,2);
  48.    if rank(v) < 2*n
  49.       Type = 'Schur';
  50.    end
  51.    p1 = v(1:n,1:n);
  52.    p2 = v((n+1):(2*n),1:n);
  53. end
  54. %
  55. % ------ Schur vector approach:
  56. %
  57. if Type == 'Schur'
  58.    [v,t,m,swap] = cschur(ham,6);
  59.    vv = [real(v(:,1:m)) imag(v(:,1:m))];
  60.    [vh,rh] = qr(vv);
  61.    p1 = vh(1:n,1:n);
  62.    p2 = vh(n+1:2*n,1:n);
  63. end
  64. %
  65. P = real(p2/p1);
  66. %
  67. perr = A'*P*A-P-A'*P*B/(R+B'*P*B)*B'*P*A+Q;
  68. %
  69. % ------ Check jw-axis roots:
  70. %
  71. lamp = eig(A-B/(R+B'*P*B)*B'*P'*A);
  72. %
  73. if max(abs(lamp)) > 1-1.e-8
  74.      wellposed='FALSE';
  75. end
  76. %
  77. % ------- End of DARESOLV.M ---- % RYC/MGS %