Class xlifepp::SelfAdjointEigenSolver#

template<typename _MatrixType>
class SelfAdjointEigenSolver#

Inheritence diagram for xlifepp::SelfAdjointEigenSolver:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "2" [label="xlifepp::GeneralizedSelfAdjointEigenSolver< _MatrixType >" tooltip="xlifepp::GeneralizedSelfAdjointEigenSolver< _MatrixType >"] "1" [label="xlifepp::SelfAdjointEigenSolver< _MatrixType >" tooltip="xlifepp::SelfAdjointEigenSolver< _MatrixType >" fillcolor="#BFBFBF"] "2" -> "1" [dir=forward tooltip="public-inheritance"] }

Collaboration diagram for xlifepp::SelfAdjointEigenSolver:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "3" [label="xlifepp::Vector< RealScalar >" tooltip="xlifepp::Vector< RealScalar >"] "2" [label="xlifepp::VectorEigenDense< RealScalar >" tooltip="xlifepp::VectorEigenDense< RealScalar >"] "5" [label="std::vector< T >" tooltip="std::vector< T >"] "7" [label="std::vector< K >" tooltip="std::vector< K >"] "4" [label="std::vector< RealScalar >" tooltip="std::vector< RealScalar >"] "1" [label="xlifepp::SelfAdjointEigenSolver< _MatrixType >" tooltip="xlifepp::SelfAdjointEigenSolver< _MatrixType >" fillcolor="#BFBFBF"] "6" [label="xlifepp::Vector< K >" tooltip="xlifepp::Vector< K >"] "9" [label="xlifepp::Vector< K >" tooltip="xlifepp::Vector< K >"] "8" [label="xlifepp::VectorEigenDense< K >" tooltip="xlifepp::VectorEigenDense< K >"] "3" -> "4" [dir=forward tooltip="public-inheritance"] "3" -> "6" [dir=forward tooltip="template-instance"] "2" -> "3" [dir=forward tooltip="public-inheritance"] "2" -> "8" [dir=forward tooltip="template-instance"] "7" -> "5" [dir=forward tooltip="template-instance"] "4" -> "5" [dir=forward tooltip="template-instance"] "1" -> "2" [dir=forward tooltip="usage"] "6" -> "7" [dir=forward tooltip="public-inheritance"] "9" -> "7" [dir=forward tooltip="public-inheritance"] "8" -> "9" [dir=forward tooltip="public-inheritance"] }

Computes eigenvalues and eigenvectors of selfadjoint matrices.

A matrix \( A \) is selfadjoint if it equals its adjoint. For real matrices, this means that the matrix is symmetric: it equals its transpose. This class computes the eigenvalues and eigenvectors of a selfadjoint matrix. These are the scalars \( \lambda \) and vectors \( v \) such that \( Av = \lambda v \). The eigenvalues of a selfadjoint matrix are always real. If \( D \) is a diagonal matrix with the eigenvalues on the diagonal, and \( V \) is a matrix with the eigenvectors as its columns, then \( A = V D V^{-1} \) (for selfadjoint matrices, the matrix \( V \) is always invertible). This is called the eigendecomposition.

The algorithm exploits the fact that the matrix is selfadjoint, making it faster and more accurate than the general purpose eigenvalue algorithms implemented in RealEigenSolver.

Only the lower triangular part of the input matrix is referenced.

Call the function compute() to compute the eigenvalues and eigenvectors of a given matrix. Alternatively, you can use the SelfAdjointEigenSolver(const MatrixType&, int) constructor which computes the eigenvalues and eigenvectors at construction time. Once the eigenvalue and eigenvectors are computed, they can be retrieved with the eigenvalues() and eigenvectors() functions.

To solve the generalized eigenvalue problem \( Av = \lambda Bv \) and the likes, see the class GeneralizedSelfAdjointEigenSolver.

See also

MatrixBase::eigenvalues(), class EigenSolver

Template Parameters:

_MatrixType – the type of the matrix of which we are computing the eigendecomposition; this is expected to be an instantiation of the Matrix class template.

Subclassed by xlifepp::GeneralizedSelfAdjointEigenSolver< _MatrixType >

Public Types

typedef NumTraits<Scalar>::RealScalar RealScalar#

Real scalar type for _MatrixType.

This is just Scalar if Scalar is real (e.g., float or double), and the type of the real part of Scalar if Scalar is complex.

typedef VectorEigenDense<RealScalar> RealVectorType#

Type for vector of eigenvalues as returned by eigenvalues().

This is a column vector with entries of type RealScalar. The length of the vector is the size of _MatrixType.

typedef MatrixType::type_t Scalar#

Scalar type for matrices of type _MatrixType.

Public Functions

inline SelfAdjointEigenSolver()#

Default constructor for fixed-size matrices.

The default constructor is useful in cases in which the user intends to perform decompositions via compute().

inline SelfAdjointEigenSolver(const MatrixType &matrix, int_t options = _computeEigenVector)#

Constructor; computes eigendecomposition of given matrix.

This constructor calls compute(const MatrixType&, int) to compute the eigenvalues of the matrix matrix. The eigenvectors are computed if options equals ComputeEigenvectors.

See also

compute(const MatrixType&, int)

Parameters:
  • matrix[in] Selfadjoint matrix whose eigendecomposition is to be computed. Only the lower triangular part of the matrix is referenced.

  • options[in] Can be ComputeEigenvectors (default) or EigenvaluesOnly.

inline SelfAdjointEigenSolver(Index size)#

Constructor, pre-allocates memory for dynamic-size matrices.

This constructor is useful for dynamic-size matrices, when the user intends to perform decompositions via compute(). The size parameter is only used as a hint. It is not an error to give a wrong size, but it may impair performance.

See also

compute() for an example

Parameters:

size[in] Positive integer, size of the matrix whose eigenvalues and eigenvectors will be computed.

SelfAdjointEigenSolver &compute(const MatrixType &matrix, int_t options = _computeEigenVector)#

Computes eigendecomposition of given matrix.

This function computes the eigenvalues of matrix. The eigenvalues() function can be used to retrieve them. If options equals ComputeEigenvectors, then the eigenvectors are also computed and can be retrieved by calling eigenvectors().

This implementation uses a symmetric QR algorithm. The matrix is first reduced to tridiagonal form using the Tridiagonalization class. The tridiagonal matrix is then brought to diagonal form with implicit symmetric QR steps with Wilkinson shift. Details can be found in Section 8.3 of Golub & Van Loan, Matrix Computations.

The cost of the computation is about \( 9n^3 \) if the eigenvectors are required and \( 4n^3/3 \) if they are not required.

This method reuses the memory in the SelfAdjointEigenSolver object that was allocated when the object was constructed, if the size of the matrix does not change.

Parameters:
  • matrix[in] Selfadjoint matrix whose eigendecomposition is to be computed. Only the lower triangular part of the matrix is referenced.

  • options[in] Can be ComputeEigenvectors (default) or EigenvaluesOnly.

Returns:

Reference to *this

inline const RealVectorType &eigenvalues() const#

Returns the eigenvalues of given matrix.

The eigenvalues are repeated according to their algebraic multiplicity, so there are as many eigenvalues as rows in the matrix. The eigenvalues are sorted in increasing order.

See also

eigenvectors(), MatrixBase::eigenvalues()

Returns:

A const reference to the column vector containing the eigenvalues.

Pre:

The eigenvalues have been computed before.

inline const MatrixType &eigenvectors() const#

Returns the eigenvectors of given matrix.

Column \( k \) of the returned matrix is an eigenvector corresponding to eigenvalue number \( k \) as returned by eigenvalues(). The eigenvectors are normalized to have (Euclidean) norm equal to one. If this object was used to solve the eigenproblem for the selfadjoint matrix \( A \), then the matrix returned by this function is the matrix \( V \) in the eigendecomposition \( A = V D V^{-1} \).

See also

eigenvalues()

Returns:

A const reference to the matrix whose columns are the eigenvectors.

Pre:

The eigenvectors have been computed before.

inline ComputationInfo info() const#

Reports whether previous computation was successful.

Returns:

Success if computation was succesful, NoConvergence otherwise.