home *** CD-ROM | disk | FTP | other *** search
- function [v,t,m,swap] = cschur(a,Type)
- %
- % [V,T,M,SWAP] = CSCHUR(A,TYPE) produces an ordered Complex Schur form
- %
- % V' * A * V = T = |T1 T12|
- % | 0 T2|,
- %
- % m = no. of stable poles (s or z plane)
- % swap = total no. of swaps.
- %
- % The unordered Schur form produced by "schur" is ordered using
- % complex Givens rotation to swap adjacent diagonal terms.
- %
- % Six types of ordering can be selected:
- %
- % Type = 1 --- Re(eig(T1)) < 0, Re(eig(T2)) > 0.
- % Type = 2 --- Re(eig(T1)) > 0, Re(eig(T2)) < 0.
- % Type = 3 --- eigenvalue real parts in descending order.
- % Type = 4 --- eigenvalue real parts in ascending order.
- % Type = 5 --- modulus of eigenvalues in descending order.
- % Type = 6 --- modulus of eigenvalues in ascending order.
- %
-
- % R. Y. Chiang & M. G. Safonov 4/4/86
- % Copyright (c) 1988 by the MathWorks, Inc.
- % All Rights Reserved.
- %---------------------------------------------------------------------
- [ma,na] = size(a);
- %
- % -------- Regular Complex Schur Decomposition :
- %
- [v,t] = schur(a);
- [v,t] = rsf2csf(v,t);
- [mt,nt] = size(t);
- dt = diag(t);
- if Type < 5
- idm = find(real(dt)<zeros(mt,1));
- else
- idm = find(abs(dt)<ones(mt,1));
- end
- [m,dum] = size(idm);
- %
- % -------- Assign I.C. for the loop counter :
- %
- pcnt = 0.; kcnt = 0.; gcnt = 0.;
-
- % The Chiang and Safonov routine ends here. The rest has
- % been replaced by optimized code.
-
- % Charles R. Denham, MathWorks, 1989.
- % Copyright (c) 1989 by the MathWorks, Inc.
- % All Rights Reserved.
-
- % Predetermine the order of sorting, to avoid possible
- % infinite loop due to round-off errors.
-
- if Type > 0 & Type < 7
-
- if Type == 1
- d = sign(real(diag(t)));
- elseif Type == 2
- d = -sign(real(diag(t)));
- elseif Type == 3
- d = -real(diag(t));
- elseif Type == 4
- d = real(diag(t));
- elseif Type == 5
- d = -abs(diag(t));
- elseif Type == 6
- d = abs(diag(t));
- end
-
- % Simple bubble sorting via Given's rotations. Matrix t
- % is re-ordered in the same manner as an ascending sort
- % of matrix d. Then, matrix v is made compatible. The
- % bubble sort code is reminiscent of the SCHORD function
- % in the Control_Toolbox, but the order of interchanges
- % is different.
-
- q = eye(nt,nt);
- swap = 0;
- okay = 1;
- while okay
- okay = 0;
- for k = 1:nt-1
- if d(k) > d(k+1)
- okay = 1;
- swap = swap + 1;
- g = givens(t(k,k+1), t(k,k)-t(k+1,k+1));
- t(:,k:k+1) = t(:,k:k+1) * g;
- t(k:k+1,:) = g' * t(k:k+1,:);
- q(:,k:k+1) = q(:,k:k+1) * g;
- temp = d(k); d(k) = d(k+1); d(k+1) = temp;
- end
- end
- end
-
- v = v * q;
-
- end
-
- % End of C.R. Denham code.