The Eigenvalue Decomposition

The eigenvalue decomposition of a square matrix writes the matrix as a product of matrices:

A = XΛX-1,

where X is a square matrix, and Λ is a diagonal matrix. In the case of a symmetric or Hermitian matrix, the eigenvalues are all real, and the eigenvectors are orthogonal or unitary. The decomposition then simplifies to:

A = XLXT,

for real matrices, and

A = XLXH,

For complex matrices. An eigenvalue λ and an eigenvector X are values such that

AX = λX.

There are as many eigenvalues and corresponding eigenvectors as there are rows or columns in the matrix. However, the eigenvalues and eigenvectors of a real matrix need not be real. In this case, they come in complex conjugate pairs. The eigenvalues and eigenvectors of a real symmetric matrix are always real.

Working with Eigenvalue Decompositions

All variations of eigenvalue decompositions (symmetric and non-symmetric, real and complex) are represented by the EigenvalueDecomposition<T> class. It has no constructors. Instead, it is created by calling the GetEigenvalueDecomposition method on the matrix. This method has two overloads. The first overload has no arguments: The second overload takes a Boolean argument that specifies whether the contents of the matrix may be destroyed during the calculation of the eigenvalue decomposition.

C#
var A = Matrix.CreateSymmetric(4, new[] {
    4.16,-3.12, 0.56,-0.10,
    0, 5.03,-0.83, 1.18,
    0,0, 0.76, 0.34,
    0,0,0, 1.18 },
    MatrixTriangle.Upper, MatrixElementOrder.RowMajor);
var eig = A.GetEigenvalueDecomposition();

The Decompose method performs the actual decomposition. This method makes a copy of the matrix if necessary. It then calls the appropriate LAPACK routine to perform the actual decomposition. This method is called by other methods as needed. You will rarely need to call it explicitly.

Once the decomposition is computed, a number of operations can be performed. However, unlike other decompositions, eigenvalue decompositions generally don't give an advantage when solving equations or computing the inverse. For these methods, the EigenvalueDecomposition<T> class simply defers to corresponding method of the base matrix.

C#
var b = Matrix.CreateFromArray(4, 2, new double[] {
    8.70, -13.35, 1.89, -4.14,
    8.30, 2.13, 1.61, 5.00 }, MatrixElementOrder.ColumnMajor);
var x = eig.Solve(b);
var invA = eig.GetInverse();
var detA = eig.GetDeterminant();

Working with Eigenvalues and Eigenvectors

Because real matrices may have complex eigenvalues and eigenvectors, the eigenvalue decomposition of a real matrix deserves some special attention.

Real matrices

For a symmetric matrix, all eigenvalues and eigenvectors are always real. The Eigenvalues property returns a vector containing the eigenvalues. The Eigenvectors property returns a matrix that has the corresponding eigenvectors as its columns:

C#
var L = eig.Eigenvalues;
var X = eig.Eigenvectors;

A non-symmetric real matrix may have complex eigenvalues, which occur in complex conjugate pairs. The corresponding eigenvectors are also complex and also come in complex conjugate pairs. The Eigenvalues and Eigenvectors return only the real eigenvalues and eigenvectors. To get all eigenvalues and eigenvectors, use the ComplexEigenvalues and ComplexEigenvectors properties.

The RawEigenvectors property returns a matrix whose columns contain all the information about the eigenvectors. For real eigenvalues, the corresponding column contains the corresponding eigenvector. For complex eigenvalues, which always occur in complex conjugate pairs, two adjoining columns contain the real and imaginary elements of the corresponding eigenvectors.

C#
var A = Matrix.CreateFromArray(4, 4, new double[] {
    0.35, 0.09, -0.44, 0.25,
    0.45, 0.07, -0.33, -0.32,
    -0.14, -0.54, -0.03, -0.13,
    -0.17, 0.35, 0.17, 0.11}, MatrixElementOrder.ColumnMajor);
var eig = A.GetEigenvalueDecomposition();

var L = eig.Eigenvalues;
var X = eig.Eigenvectors;
var complexL = eig.ComplexEigenvalues;
var complexX = eig.ComplexEigenvectors;
var rawX = eig.RawEigenvectors;

Complex matrices

The eigenvalues and eigenvectors of a complex matrix are also complex. The Eigenvalues property returns a vector containing the eigenvalues. The Eigenvectors property returns a matrix that has the corresponding eigenvectors as its columns.

The eigenvalues of a Hermitian matrix are real. This simply means that the imaginary component of the eigenvalue vector is identically zero.

The ComplexEigenvalues, ComplexEigenvectors, and RawEigenvectors properties are meaningless for complex eigenvalue decompositions.