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 matrix, the eigenvalues are all real, and the eigenvectors are orthogonal.
The decomposition then simplifies to:
A = XLXT,
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 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.
In the Extreme Optimization Mathematics Library for .NET, both the symmetric
and the non-symmetric eigenvalue decompositions are
implemented by the EigenvalueDecomposition class.
The EigenvalueDecomposition class
The EigenvalueDecomposition class
represents the eigenvalue decomposition of a real matrix. 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 parameters:
| C# |
Copy
|
SymmetricMatrix aED = Matrix.CreateSymmetric(4,
new double[]
{
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
}, MatrixTriangleMode.Lower);
SymmetricEigenvalueDecomposition ed = aED.GetEigenvalueDecomposition();
|
| Visual Basic |
Copy
|
Dim aED As SymmetricMatrix = Matrix.CreateSymmetric(4, _
New Double() _
{ _
4.16, -3.12, 0.56, -0.1, _
0, 5.03, -0.83, 1.18, _
0, 0, 0.76, 0.34, _
0, 0, 0, 1.18 _
}, MatrixTriangleMode.Lower)
Dim ed As SymmetricEigenvalueDecomposition = aED.GetEigenvalueDecomposition()
|
The second overload takes a Boolean parameter that specifies whether the contents of the
matrix may be destroyed during the calculation of the eigenvalue decomposition.
| C# |
Copy
|
SymmetricEigenvalueDecomposition ed2 = aED.GetEigenvalueDecomposition(true);
|
| Visual Basic |
Copy
|
Dim ed2 As SymmetricEigenvalueDecomposition = aED.GetEigenvalueDecomposition(True)
|
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 in much less time.
However, unlike other decompositions, the non-symmetric eigenvalue decomposition does not give
an advantage when solving equations or computing the inverse. For these methods,
the EigenvalueDecomposition class simply defers to
corresponding method of the base matrix.
| C# |
Copy
|
DenseMatrix bED = Matrix.Create(4, 2,
new double[] {8.70,-13.35,1.89,-4.14,8.30,2.13,1.61,5.00});
Matrix xED = ed.Solve(bED);
Console.WriteLine("x = {0}", xED);
Console.WriteLine("Inv A = {0}", ed.GetInverse().ToString("F4"));
Console.WriteLine("Det A = {0}", ed.GetDeterminant());
|
| Visual Basic |
Copy
|
Dim bED As DenseMatrix = Matrix.Create(4, 2, _
New Double() {8.7, -13.35, 1.89, -4.14, 8.3, 2.13, 1.61, 5.0})
Dim xED As Matrix = ed.Solve(bED)
Console.WriteLine("x = {0}", xED)
Console.WriteLine("Inv A = {0}", ed.GetInverse().ToString("F4"))
Console.WriteLine("Det A = {0}", ed.GetDeterminant())
|
The ComplexEigenvalues
property returns a ComplexVector that contains
the eigenvalues of the matrix. This is a complex vector because the eigenvalues may be complex.
The ComplexEigenvectors property
returns a ComplexMatrix whose columns contain the
corresponding eigenvectors of the matrix.
The RealEigenvalues
property returns a Vector that contains
only the real eigenvalues of the matrix. The RealEigenvectors property
returns a Matrix whose columns contain
only the eigenvectors corresponding to the real eigenvalues of the matrix.
For a symmetric matrix, all eigenvalues and eigenvectors are always real:
| C# |
Copy
|
Console.WriteLine("L = {0}", ed.Eigenvalues.ToString("F4"));
Console.WriteLine("X = {0}", ed.Eigenvectors.ToString("F4"));
|
| Visual Basic |
Copy
|
Console.WriteLine("L = {0}", ed.Eigenvalues.ToString("F4"))
Console.WriteLine("X = {0}", ed.Eigenvectors.ToString("F4"))
|
For a non-symmetric matrix, complex eigenvalues and eigenvectors may occur in complex conjugate pairs.
In this case, they are omitted from the values returned by the
RealEigenvalues
and RealEigenvectors
properties.
The RawEigenvectors
property returns a DenseMatrix 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 components of the corresponding eigenvectors.
| C# |
Copy
|
Console.WriteLine("L = {0}", ed.Eigenvalues.ToString("F4"));
Console.WriteLine("X = {0}", ed.Eigenvectors.ToString("F4"));
Console.WriteLine("L(real) = {0}", ed.RealEigenvalues.ToString("F4"));
Console.WriteLine("X(real) = {0}", ed.RealEigenvectors.ToString("F4"));
Console.WriteLine("X(raw) = {0}", ed.RawEigenvectors.ToString("F4"));
|
| Visual Basic |
Copy
|
Console.WriteLine("L = {0}", ed.Eigenvalues.ToString("F4"))
Console.WriteLine("X = {0}", ed.Eigenvectors.ToString("F4"))
Console.WriteLine("L(real) = {0}", ed.RealEigenvalues.ToString("F4"))
Console.WriteLine("X(real) = {0}", ed.RealEigenvectors.ToString("F4"))
Console.WriteLine("X(raw) = {0}", ed.RawEigenvectors.ToString("F4"))
|
The managed implementation of the symmetric eigenvalue decomposition is based on the LINPACK routines TRED2 and
TQL2. The non-symmetric eigenvalue decomposition is based on the LINPACK routines ELMHES and HQR2.
The native version uses the LAPACK routine DSYEVR for the symmetric case and DGEEV for the non-symmetric case.