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

  1. % function [v,t,flgout,reig_min] = csord(a,epp,flgord,flgjw,flgeig)
  2. %
  3. %  This function produces an ordered complex schur matrix, T,
  4. %  where
  5. %              v' * a * v  = t = |t11  t12|
  6. %                                | 0   t22|.
  7. %  and V'V = eye().
  8. %  The MATLAB function SCHUR is called, which results in an 
  9. %  unordered Schur form matrix. A subroutine called CGIVENS
  10. %  is used to form a complex Givens rotation matrix which
  11. %  orders the T matrix in a user-defined manner. A series
  12. %  of input flags can be set:
  13. %
  14. %  EPP           user supplied zero tolerance (default EPP=1e-15)
  15. %  FLGORD = 0    order eigenvalues in ascending real part (default)
  16. %         = 1    partial real part ordering, <0 , =0, >0
  17. %  FLGJW  = 0    no exit condition on eigenvalue location (default)
  18. %         = 1    exit if abs(real(eigenvalue_i)) < EPP
  19. %  FLGEIG = 0    no exit condition on half-plane eigenvalue 
  20. %                distribution (default)
  21. %         = 1    exit if 
  22. %                length(real(eigenvalue)>0) ~= length(real(eigenvalue)<0)
  23. %
  24. %
  25. %  The output flag FLGOUT is nominally 0. If there are jw-axis
  26. %  eigenvalues, FLGOUT is set to 1. If there are an unequal
  27. %  number of positive and negative eigenvalues, FLGOUT is set
  28. %  to 2. If both conditions occur, FLGOUT = 3. The minimum real part
  29. %  of the eigenvalues is output in REIG_MIN.
  30. %
  31. %  See also: RIC_SCHR, SCHUR, and RSF2CSF.
  32.  
  33. %  The RIC_SCHR routine uses CSORD to solve stabilizing
  34. %  solutions to matrix Ricatti equations. In that case, the
  35. %  a matrix has a special structure, and there are failure modes
  36. %  which can be flagged, thus avoiding extra, unnecessary
  37. %  computations. 
  38. %  Wes Wang made change to limit the matrix to be a square matrix.
  39.  
  40. function [v,t,flgout,reig_min] = csord(a,epp,flgord,flgjw,flgeig)
  41.  
  42.  if nargin < 1
  43.    disp(['usage: [v,t,flgout] = csord(a,epp,flgord,flgjw,flgeig)'])
  44.    return
  45.  elseif nargin == 1
  46.    epp = 1e-15;
  47.    flgord = 0;
  48.    flgjw = 0;
  49.    flgeig = 0;
  50.   elseif nargin == 2
  51.    flgord = 0;
  52.    flgjw = 0;
  53.    flgeig = 0;
  54.   elseif nargin == 3
  55.    flgjw = 0;
  56.    flgeig = 0;
  57.   elseif nargin == 4
  58.    flgeig = 0;
  59.   end
  60.    
  61.  [nc,nr] = size(a);
  62. %%%%%%%%%% begine the change made by Wes Wang %%%%%%%%
  63.  if nc ~= nr,
  64.    disp('Matrix must be square.')
  65.    return
  66.  end;
  67. %%%%%%%%%% end the change made by Wes Wang %%%%%%%%%%%
  68.  flgout = 0;
  69. %
  70. % complex schur decomposition 
  71. %
  72.  [v,t] = schur(a);
  73.  [v,t] = rsf2csf(v,t); % change into complex Schur form if it isn't
  74.  [ntc,ntr] = size(t); 
  75. %
  76. % check if there are any jw-axis eigenvalues in the matrix (used
  77. % in HINFSYN and HINFFI routines)
  78. %
  79. reig_min = min(abs(real(diag(t))));
  80. if min(abs(real(diag(t)))) < epp
  81.   flgout = 1;                        % there is a jw axis eigenvalue
  82.   if flgjw == 1
  83.     t = [];
  84.     v = [];
  85.     return
  86.   end
  87. end
  88. neg_eig = length(find(real(diag(t))<0));
  89. pos_eig = length(find(real(diag(t))>0));
  90. if neg_eig ~= ntc/2 | pos_eig ~= ntc/2
  91.   if flgout == 0
  92.     flgout = 2;
  93.   else
  94.     flgout = 3;
  95.   end
  96.   if flgeig == 1
  97.     t = [];
  98.     v = [];
  99.     return
  100.   end
  101. end
  102. % order evals
  103.  if flgord == 1                      % partial ordering -0+
  104.    if flgjw == 1                     % Riccati solution
  105.      for i = 1 : ntc*ntc/4
  106.        for k = 1 : (ntc-1)
  107.          if (real(t(k,k))>0.) & (real(t(k+1,k+1))<0.)
  108.            [c,s] = cgivens( t(k,k+1), t(k,k)-t(k+1,k+1) );
  109.            t(:,k:k+1) = t(:,k:k+1)*[c s;-s' c];
  110.            t(k:k+1,:) = [c s;-s' c]'*t(k:k+1,:);
  111.        v(:,k:k+1) = v(:,k:k+1)*[c s;-s' c];
  112.          end
  113.        end
  114.        mxneg = max(find(real(diag(t))<0));
  115.        mnpos = min(find(real(diag(t))>0));
  116. %
  117. %    check if the ordering of the Schur matrix is finished
  118. %
  119.        if (mxneg <  mnpos)
  120.          break               % done partial ordering
  121.        end
  122.      end
  123.    else
  124.      for i = 1 : ntc*ntc/4
  125.        for k = 1 : (ntc-1)
  126.          if (real(t(k,k))>=0.) & (real(t(k+1,k+1))<=0.)
  127.            [c,s] = cgivens( t(k,k+1), t(k,k)-t(k+1,k+1) );
  128.            t(:,k:k+1) = t(:,k:k+1)*[c s;-s' c];
  129.            t(k:k+1,:) = [c s;-s' c]'*t(k:k+1,:);
  130.        v(:,k:k+1) = v(:,k:k+1)*[c s;-s' c];
  131.          end
  132.        end
  133.        mxneg = max(find(real(diag(t))<0));
  134.        mxzer = max(find(real(diag(t))==0));
  135.        mnzer = min(find(real(diag(t))==0));
  136.        mnpos = min(find(real(diag(t))>0));
  137. %
  138. %    check if the ordering of the Schur matrix is finished
  139. %
  140.        if (mxneg < mnzer) & (mxzer < mnpos)
  141.          break               % done partial ordering
  142.        end
  143.      end
  144.    end %if flgjw
  145.  else                         %  full ordering
  146.    for i = 1 : ntc*ntc/4
  147.      for k = 1 : (ntc-1)
  148.        if (real(t(k,k)) > real(t(k+1,k+1)))
  149.          [c,s] = cgivens( t(k,k+1), t(k,k)-t(k+1,k+1) );
  150.          t(:,k:k+1) = t(:,k:k+1)*[c s;-s' c];
  151.          t(k:k+1,:) = [c s;-s' c]'*t(k:k+1,:);
  152.             v(:,k:k+1) = v(:,k:k+1)*[c s;-s' c];
  153.        end
  154.      end
  155.      if min(diff(real(diag(t)))) >= 0
  156.        break               % done full ordering
  157.      end
  158.    end
  159.  end
  160. %
  161. % Copyright MUSYN INC 1991,  All Rights Reserved
  162.