%% Reorder Schur Factorization
% Compute the Schur factors of a matrix, then reorder the factors according to a specified ordering of the eigenvalues.
%
% Find the Schur factorization of a matrix X. The Schur factorization produces an upper quasitriangular matrix T and a unitary matrix U such that X={\textrm{UTU}}^*.

X = magic(6);
[U,T] = schur(X)

%
% Since T is triangular, the diagonal of T contains the eigenvalues of the original matrix X.
% Reorder the Schur factorization so that the eigenvalues are in two clusters, with the cluster of negative eigenvalues  appearing first along the diagonal of TS.

[US,TS] = ordschur(U,T,'lhp')

% Copyright 2012 The MathWorks, Inc.