Class xlifepp::RealEigenSolver#

template<typename _MatrixType>
class RealEigenSolver#

Collaboration diagram for xlifepp::RealEigenSolver:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "11" [label="xlifepp::HessenbergDecomposition< MatrixType >" tooltip="xlifepp::HessenbergDecomposition< MatrixType >"] "10" [label="xlifepp::RealSchur< MatrixType >" tooltip="xlifepp::RealSchur< MatrixType >"] "3" [label="xlifepp::Vector< ComplexScalar >" tooltip="xlifepp::Vector< ComplexScalar >"] "13" [label="xlifepp::Vector< Scalar >" tooltip="xlifepp::Vector< Scalar >"] "2" [label="xlifepp::VectorEigenDense< ComplexScalar >" tooltip="xlifepp::VectorEigenDense< ComplexScalar >"] "12" [label="xlifepp::VectorEigenDense< Scalar >" tooltip="xlifepp::VectorEigenDense< Scalar >"] "5" [label="std::vector< T >" tooltip="std::vector< T >"] "4" [label="std::vector< ComplexScalar >" tooltip="std::vector< ComplexScalar >"] "7" [label="std::vector< K >" tooltip="std::vector< K >"] "14" [label="std::vector< Scalar >" tooltip="std::vector< Scalar >"] "15" [label="xlifepp::HessenbergDecomposition< _MatrixType >" tooltip="xlifepp::HessenbergDecomposition< _MatrixType >"] "1" [label="xlifepp::RealEigenSolver< _MatrixType >" tooltip="xlifepp::RealEigenSolver< _MatrixType >" fillcolor="#BFBFBF"] "16" [label="xlifepp::RealSchur< _MatrixType >" tooltip="xlifepp::RealSchur< _MatrixType >"] "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 >"] "11" -> "12" [dir=forward tooltip="usage"] "11" -> "15" [dir=forward tooltip="template-instance"] "10" -> "11" [dir=forward tooltip="usage"] "10" -> "16" [dir=forward tooltip="template-instance"] "3" -> "4" [dir=forward tooltip="public-inheritance"] "3" -> "6" [dir=forward tooltip="template-instance"] "13" -> "14" [dir=forward tooltip="public-inheritance"] "13" -> "6" [dir=forward tooltip="template-instance"] "2" -> "3" [dir=forward tooltip="public-inheritance"] "2" -> "8" [dir=forward tooltip="template-instance"] "12" -> "13" [dir=forward tooltip="public-inheritance"] "12" -> "8" [dir=forward tooltip="template-instance"] "4" -> "5" [dir=forward tooltip="template-instance"] "7" -> "5" [dir=forward tooltip="template-instance"] "14" -> "5" [dir=forward tooltip="template-instance"] "15" -> "12" [dir=forward tooltip="usage"] "1" -> "2" [dir=forward tooltip="usage"] "1" -> "10" [dir=forward tooltip="usage"] "16" -> "11" [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 general matrices.

The eigenvalues and eigenvectors of a matrix \( A \) are scalars \( \lambda \) and vectors \( v \) such that \( Av = \lambda v \). 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 = V D \). The matrix \( V \) is almost always invertible, in which case we have \( A = V D V^{-1} \). This is called the eigendecomposition.

The eigenvalues and eigenvectors of a matrix may be complex, even when the matrix is real. However, we can choose real matrices \( V \) and \( D \) satisfying \( A V = V D \), just like the eigendecomposition, if the matrix \( D \) is not required to be diagonal, but if it is allowed to have blocks of the form

\[\begin{split} \left(\begin{array}{cc} u & v \\ -v & u \end{array}\right) \end{split}\]
(where \( u \) and \( v \) are real numbers) on the diagonal. These blocks correspond to complex eigenvalue pairs \( u \pm iv \). We call this variant of the eigendecomposition the pseudo-eigendecomposition.

Call the function compute() to compute the eigenvalues and eigenvectors of a given matrix. Alternatively, you can use the RealEigenSolver(const MatrixType&, bool) 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. The pseudoEigenvalueMatrix() and pseudoEigenvectors() methods allow the construction of the pseudo-eigendecomposition.

The documentation for RealEigenSolver(const MatrixType&, bool) contains an example of the typical use of this class.

See also

MatrixBase::eigenvalues(), class ComplexEigenSolver, class SelfAdjointEigenSolver

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. Currently, only real matrices are supported.

Note

The implementation is adapted from JAMA (public domain). Their code is based on EISPACK.

Public Types

typedef NumTraits<Scalar>::ComplexScalar ComplexScalar#

Complex scalar type for MatrixType.

This is std::complex<Scalar> if Scalar is real (e.g., float or double) and just Scalar if Scalar is complex.

typedef VectorEigenDense<ComplexScalar> EigenvalueType#

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

This is a column vector with entries of type ComplexScalar. The length of the vector is the size of MatrixType.

typedef MatrixEigenDense<ComplexScalar> EigenvectorsType#

Type for matrix of eigenvectors as returned by eigenvectors().

This is a square matrix with entries of type ComplexScalar. The size is the same as the size of MatrixType.

typedef _MatrixType MatrixType#

Synonym for the template parameter _MatrixType.

typedef MatrixType::type_t Scalar#

Scalar type for matrices of type MatrixType.

Public Functions

inline RealEigenSolver()#

Default constructor.

The default constructor is useful in cases in which the user intends to perform decompositions via RealEigenSolver::compute(const MatrixType&, bool).

See also

compute() for an example.

inline RealEigenSolver(const MatrixType &matrix, bool computeEigenvectors = true)#

Constructor; computes eigendecomposition of given matrix.

This constructor calls compute() to compute the eigenvalues and eigenvectors.

See also

compute()

Parameters:
  • matrix[in] Square matrix whose eigendecomposition is to be computed.

  • computeEigenvectors[in] If true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed.

inline RealEigenSolver(Index size)#

Default constructor with memory preallocation.

Like the default constructor but with preallocation of the internal data according to the specified problem size.

RealEigenSolver<MatrixType> &compute(const MatrixType &matrix, bool computeEigenvectors = true)#

Computes eigendecomposition of given matrix.

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

The matrix is first reduced to real Schur form using the RealSchur class. The Schur decomposition is then used to compute the eigenvalues and eigenvectors.

The cost of the computation is dominated by the cost of the Schur decomposition, which is very approximately \( 25n^3 \) (where \( n \) is the size of the matrix) if computeEigenvectors is true, and \( 10n^3 \) if computeEigenvectors is false.

This method reuses of the allocated data in the RealEigenSolver object.

Parameters:
  • matrix[in] Square matrix whose eigendecomposition is to be computed.

  • computeEigenvectors[in] If true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed.

Returns:

Reference to *this

inline const EigenvalueType &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 not sorted in any particular order.

See also

eigenvectors(), pseudoEigenvalueMatrix(), MatrixBase::eigenvalues()

Returns:

A const reference to the column vector containing the eigenvalues.

Pre:

Either the constructor RealEigenSolver(const MatrixType&,bool) or the member function compute(const MatrixType&, bool) has been called before.

EigenvectorsType 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. The matrix returned by this function is the matrix \( V \) in the eigendecomposition \( A = V D V^{-1} \), if it exists.

Returns:

Matrix whose columns are the (possibly complex) eigenvectors.

Pre:

Either the constructor RealEigenSolver(const MatrixType&,bool) or the member function compute(const MatrixType&, bool) has been called before, and computeEigenvectors was set to true (the default).

MatrixType pseudoEigenvalueMatrix() const#

Returns the block-diagonal matrix in the pseudo-eigendecomposition.

The matrix \( D \) returned by this function is real and block-diagonal. The blocks on the diagonal are either 1-by-1 or 2-by-2 blocks of the form \(\left(\begin{array}{cc} u & v \\ -v & u \end{array}\right) \). These blocks are not sorted in any particular order. The matrix \( D \) and the matrix \( V \) returned by pseudoEigenvectors() satisfy \( AV = VD \).

See also

pseudoEigenvectors() for an example, eigenvalues()

Returns:

A block-diagonal matrix.

Pre:

Either the constructor RealEigenSolver(const MatrixType&,bool) or the member function compute(const MatrixType&, bool) has been called before.

inline const MatrixType &pseudoEigenvectors() const#

Returns the pseudo-eigenvectors of given matrix.

The real matrix \( V \) returned by this function and the block-diagonal matrix \( D \) returned by pseudoEigenvalueMatrix() satisfy \( AV = VD \).

Returns:

Const reference to matrix whose columns are the pseudo-eigenvectors.

Pre:

Either the constructor RealEigenSolver(const MatrixType&,bool) or the member function compute(const MatrixType&, bool) has been called before, and computeEigenvectors was set to true (the default).