The Generalized Eigenvalue Decomposition
The generalized eigenvalue decomposition of a pair of square matrices computes scalars λ, μ and vectors x, y, such that
Ax = λBx ,
and
μAy = By ,
When λ and μ are not both zero, then the two problems are equivalent with x = y and μ = 1/λ. To cover all cases, a generalized eigenvalue decomposition returns two values whose quotient, if it exists, is equal to the eigenvalue.
The values λ and μ are eigenvalues and the vectors x and y are eigenvectors.
The case where A and B are both symmetric or Hermitian and B is also positive definite is special. In this case, all eigenvalues are real and the eigenvectors are orthogonal with respect to B. That is, if X is the matrix whose columns are the eigenvectors, and I is the identity matrix, then (for real matrices)
XTBX = I.
When B is the identity matrix, then the generalized eigenvalue decomposition reduces to the standard eigenvalue decomposition.
There are as many eigenvalues and corresponding eigenvectors as there are rows or columns in the matrices. 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 Generalized Eigenvalue Decompositions
All variations of eigenvalue decompositions (real symmetric and non-symmetric, complex Hermitian and non-Hermitian) are represented by the GeneralizedEigenvalueDecomposition<T> class. It has no constructors. Instead, it is created by calling the GetEigenvalueDecomposition method on the primary matrix (A). This method has two overloads. The first overload has one argument: the secondary matrix (B). Both matrices must be square. The second overload takes an additional Boolean argument that specifies whether the contents of the matrices may be destroyed during the calculation of the eigenvalue decomposition.
var A = Matrix.CreateSymmetric(3, new double[]
{ 1,2,3, 2,4,9, 3,9,15 },
MatrixTriangle.Upper, MatrixElementOrder.ColumnMajor);
var B = Matrix.CreateSymmetric(3, new double[]
{ 3,-2,3, -2,6,-9, 3,-9,17 },
MatrixTriangle.Upper, MatrixElementOrder.ColumnMajor);
var geig = A.GetEigenvalueDecomposition(B);
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.
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 symmetric matrices where the secondary matrix is positive definite, 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:
var L = geig.Eigenvalues;
var X = geig.Eigenvectors;
Otherwise, there may be 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.
var A = Matrix.CreateFromArray(4, 4, new double[] {
3.9, 4.3, 4.3, 4.4,
12.5, 21.5, 21.5, 26.0,
-34.5, -47.5, -43.5,-46.0,
-0.5, 7.5, 3.5, 6.0 },
MatrixElementOrder.ColumnMajor);
var B = Matrix.CreateFromArray(4, 4, new double[] {
1.0, 1.0, 1.0, 1.0,
2.0, 3.0, 3.0, 3.0,
-3.0, -5.0, -4.0, -4.0,
1.0, 4.0, 3.0, 4.0 },
MatrixElementOrder.ColumnMajor);
var geig = A.GetEigenvalueDecomposition(B);
var L = geig.Eigenvalues;
var X = geig.Eigenvectors;
var complexL = geig.ComplexEigenvalues;
var complexX = geig.ComplexEigenvectors;
var rawX = geig.RawEigenvectors;
Complex matrices
The generalized eigenvalues and eigenvalues of a pair of complex matrices 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 generalized eigenvalues of a pair of Hermitian matrices where the secondary matrix is also positive definite, are also 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.
Singular secondary matrices
If the secondary matrix B is singular, then one or more of the generalized eigenvalues of the pair is infinite. The generalized eigenvalues can also be returned as pairs whose quotient is the generalized eigenvalue. When the denominator of the quotient is zero, the generalized eigenvalue is infinite.
Three properties give access to the quotient form of the generalized eigenvalues. The EigenvalueDenominators property returns a vector containing the denominators of the quotients. For real matrices, it is always real. The EigenvalueNumerators property returns a vector containing the numerators of the quotients. As with the generalized eigenvalues themselves, this property only returns real numerators for real matrices. To access the the full set of numerators, use the ComplexEigenvalueNumerators property.