%% Eigenvalues of Nondiagonalizable (Defective) Matrix
% Create a 3-by-3 matrix.

A = [3 1 0; 0 3 1; 0 0 3];

%
% Calculate the eigenvalues and right eigenvectors of A.

[V,D] = eig(A)

% A has repeated eigenvalues and the eigenvectors are not independent. This means that A is not diagonalizable and is, therefore, defective.
%
% Verify that V and D satisfy the equation, A*V = V*D, even though A is defective.

A*V - V*D

% Ideally, the eigenvalue decomposition satisfies the relationship. Since eig performs the decomposition using floating-point computations, then A*V can, at best, approach V*D. In other words, A*V - V*D is close to, but not exactly, 0.
% Copyright 2012 The MathWorks, Inc.