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

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