%% Transform Real Schur Form to Complex Schur Form
% Apply Schur decomposition to a real matrix, and then transform the matrix factors so that the eigenvalues are directly on the main diagonal.
%
% Create a real matrix and calculate the Schur decomposition. The U factor is unitary so that U^T U=I_N, and the T factor is in real Schur form with complex conjugate eigenvalue pairs expressed as 2-by-2 blocks on the diagonal.

X = [1     1     1     3
     1     2     1     1
     1     1     3     1
    -2     1     1     4];
[U,T] = schur(X)

% T has two real eigenvalues on the diagonal and one 2-by-2 block representing a complex conjugate pair of eigenvalues.
%
% Transform U and T so that Tnew is upper triangular with the eigenvalues on the diagonal, and Unew satisfies X = Unew*Tnew*Unew'.

[Unew,Tnew] = rsf2csf(U,T)

% Copyright 2020 The MathWorks, Inc.