%% Transform Complex Diagonal Matrix into Real Block Diagonal Matrix
% Calculate the eigenvalues and eigenvectors of a real matrix, and then transform the complex conjugate eigenvalue pairs into real blocks.
%
% Find the eigenvalues and eigenvectors of a real matrix.

X = [1   1   1   1   1 
     0   4   5   1   1 
     0  -5   4   1   1 
     0   0   2   3   1
     0   0  -3  -2   1];
[V,D] = eig(X)

% D contains one real eigenvalue and two pairs of complex conjugate eigenvalues.
%
% Transform V and D so that Dnew is in real block diagonal form and Vnew satisfies X*Vnew = Vnew*Dnew

[Vnew,Dnew] = cdf2rdf(V,D)

% Dnew still has the real eigenvalue, but the complex conjugate eigenvalues are replaced with 2-by-2 blocks.
% Copyright 2020 The MathWorks, Inc.