Eigne Matrix Class Library

Dependents:   Eigen_test Odometry_test AttitudeEstimation_usingTicker MPU9250_Quaternion_Binary_Serial ... more

Embed: (wiki syntax)

« Back to documentation index

GeneralizedSelfAdjointEigenSolver< _MatrixType > Class Template Reference

GeneralizedSelfAdjointEigenSolver< _MatrixType > Class Template Reference
[Eigenvalues module]

More...

#include <GeneralizedSelfAdjointEigenSolver.h>

Inherits Eigen::SelfAdjointEigenSolver< _MatrixType >.

Public Types

typedef MatrixType::Scalar Scalar
 Scalar type for matrices of type _MatrixType.
typedef NumTraits< Scalar >::Real RealScalar
 Real scalar type for _MatrixType.
typedef
internal::plain_col_type
< MatrixType, RealScalar >
::type 
RealVectorType
 Type for vector of eigenvalues as returned by eigenvalues().

Public Member Functions

 GeneralizedSelfAdjointEigenSolver ()
 Default constructor for fixed-size matrices.
 GeneralizedSelfAdjointEigenSolver (Index size)
 Constructor, pre-allocates memory for dynamic-size matrices.
 GeneralizedSelfAdjointEigenSolver (const MatrixType &matA, const MatrixType &matB, int options=ComputeEigenvectors|Ax_lBx)
 Constructor; computes generalized eigendecomposition of given matrix pencil.
GeneralizedSelfAdjointEigenSolvercompute (const MatrixType &matA, const MatrixType &matB, int options=ComputeEigenvectors|Ax_lBx)
 Computes generalized eigendecomposition of given matrix pencil.
SelfAdjointEigenSolvercompute (const MatrixType &matrix, int options=ComputeEigenvectors)
 Computes eigendecomposition of given matrix.
SelfAdjointEigenSolvercomputeDirect (const MatrixType &matrix, int options=ComputeEigenvectors)
 Computes eigendecomposition of given matrix using a direct algorithm.
const EigenvectorsTypeeigenvectors () const
 Returns the eigenvectors of given matrix.
const RealVectorTypeeigenvalues () const
 Returns the eigenvalues of given matrix.
MatrixType operatorSqrt () const
 Computes the positive-definite square root of the matrix.
MatrixType operatorInverseSqrt () const
 Computes the inverse square root of the matrix.
ComputationInfo info () const
 Reports whether previous computation was successful.

Static Public Attributes

static const int m_maxIterations = 30
 Maximum number of iterations.

Detailed Description

template<typename _MatrixType>
class Eigen::GeneralizedSelfAdjointEigenSolver< _MatrixType >

Computes eigenvalues and eigenvectors of the generalized selfadjoint eigen problem

Template Parameters:
_MatrixTypethe type of the matrix of which we are computing the eigendecomposition; this is expected to be an instantiation of the Matrix class template.

This class solves the generalized eigenvalue problem $ Av = \lambda Bv $. In this case, the matrix $ A $ should be selfadjoint and the matrix $ B $ should be positive definite.

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 GeneralizedSelfAdjointEigenSolver(const MatrixType&, 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.

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

See also:
class SelfAdjointEigenSolver, class EigenSolver, class ComplexEigenSolver

Definition at line 48 of file GeneralizedSelfAdjointEigenSolver.h.


Member Typedef Documentation

typedef NumTraits<Scalar>::Real RealScalar [inherited]

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.

Definition at line 92 of file SelfAdjointEigenSolver.h.

typedef internal::plain_col_type<MatrixType, RealScalar>::type RealVectorType [inherited]

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.

Definition at line 101 of file SelfAdjointEigenSolver.h.

typedef MatrixType::Scalar Scalar [inherited]

Scalar type for matrices of type _MatrixType.

Definition at line 81 of file SelfAdjointEigenSolver.h.


Constructor & Destructor Documentation

Default constructor for fixed-size matrices.

The default constructor is useful in cases in which the user intends to perform decompositions via compute(). This constructor can only be used if _MatrixType is a fixed-size matrix; use GeneralizedSelfAdjointEigenSolver(Index) for dynamic-size matrices.

Definition at line 63 of file GeneralizedSelfAdjointEigenSolver.h.

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

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

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

Definition at line 77 of file GeneralizedSelfAdjointEigenSolver.h.

GeneralizedSelfAdjointEigenSolver ( const MatrixType &  matA,
const MatrixType &  matB,
int  options = ComputeEigenvectors|Ax_lBx 
)

Constructor; computes generalized eigendecomposition of given matrix pencil.

Parameters:
[in]matASelfadjoint matrix in matrix pencil. Only the lower triangular part of the matrix is referenced.
[in]matBPositive-definite matrix in matrix pencil. Only the lower triangular part of the matrix is referenced.
[in]optionsA or-ed set of flags {ComputeEigenvectors,EigenvaluesOnly} | {Ax_lBx,ABx_lx,BAx_lx}. Default is ComputeEigenvectors|Ax_lBx.

This constructor calls compute(const MatrixType&, const MatrixType&, int) to compute the eigenvalues and (if requested) the eigenvectors of the generalized eigenproblem $ Ax = \lambda B x $ with matA the selfadjoint matrix $ A $ and matB the positive definite matrix $ B $. Each eigenvector $ x $ satisfies the property $ x^* B x = 1 $. The eigenvectors are computed if options contains ComputeEigenvectors.

In addition, the two following variants can be solved via options:

  • ABx_lx: $ ABx = \lambda x $
  • BAx_lx: $ BAx = \lambda x $

Example:

Output:

See also:
compute(const MatrixType&, const MatrixType&, int)

Definition at line 107 of file GeneralizedSelfAdjointEigenSolver.h.


Member Function Documentation

GeneralizedSelfAdjointEigenSolver< MatrixType > & compute ( const MatrixType &  matA,
const MatrixType &  matB,
int  options = ComputeEigenvectors|Ax_lBx 
)

Computes generalized eigendecomposition of given matrix pencil.

Parameters:
[in]matASelfadjoint matrix in matrix pencil. Only the lower triangular part of the matrix is referenced.
[in]matBPositive-definite matrix in matrix pencil. Only the lower triangular part of the matrix is referenced.
[in]optionsA or-ed set of flags {ComputeEigenvectors,EigenvaluesOnly} | {Ax_lBx,ABx_lx,BAx_lx}. Default is ComputeEigenvectors|Ax_lBx.
Returns:
Reference to *this

Accoring to options, this function computes eigenvalues and (if requested) the eigenvectors of one of the following three generalized eigenproblems:

  • Ax_lBx: $ Ax = \lambda B x $
  • ABx_lx: $ ABx = \lambda x $
  • BAx_lx: $ BAx = \lambda x $ with matA the selfadjoint matrix $ A $ and matB the positive definite matrix $ B $. In addition, each eigenvector $ x $ satisfies the property $ x^* B x = 1 $.

The eigenvalues() function can be used to retrieve the eigenvalues. If options contains ComputeEigenvectors, then the eigenvectors are also computed and can be retrieved by calling eigenvectors().

The implementation uses LLT to compute the Cholesky decomposition $ B = LL^* $ and computes the classical eigendecomposition of the selfadjoint matrix $ L^{-1} A (L^*)^{-1} $ if options contains Ax_lBx and of $ L^{*} A L $ otherwise. This solves the generalized eigenproblem, because any solution of the generalized eigenproblem $ Ax = \lambda B x $ corresponds to a solution $ L^{-1} A (L^*)^{-1} (L^* x) = \lambda (L^* x) $ of the eigenproblem for $ L^{-1} A (L^*)^{-1} $. Similar statements can be made for the two other variants.

Example:

Output:

See also:
GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int)

Definition at line 164 of file GeneralizedSelfAdjointEigenSolver.h.

SelfAdjointEigenSolver< MatrixType > & compute ( const MatrixType &  matrix,
int  options = ComputeEigenvectors 
) [inherited]

Computes eigendecomposition of given matrix.

Parameters:
[in]matrixSelfadjoint matrix whose eigendecomposition is to be computed. Only the lower triangular part of the matrix is referenced.
[in]optionsCan be ComputeEigenvectors (default) or EigenvaluesOnly.
Returns:
Reference to *this

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.

Example:

Output:

See also:
SelfAdjointEigenSolver(const MatrixType&, int)

Definition at line 392 of file SelfAdjointEigenSolver.h.

SelfAdjointEigenSolver< MatrixType > & computeDirect ( const MatrixType &  matrix,
int  options = ComputeEigenvectors 
) [inherited]

Computes eigendecomposition of given matrix using a direct algorithm.

This is a variant of compute(const MatrixType&, int options) which directly solves the underlying polynomial equation.

Currently only 3x3 matrices for which the sizes are known at compile time are supported (e.g., Matrix3d).

This method is usually significantly faster than the QR algorithm but it might also be less accurate. It is also worth noting that for 3x3 matrices it involves trigonometric operations which are not necessarily available for all scalar types.

See also:
compute(const MatrixType&, int options)

Definition at line 732 of file SelfAdjointEigenSolver.h.

const RealVectorType& eigenvalues (  ) const [inherited]

Returns the eigenvalues of given matrix.

Returns:
A const reference to the column vector containing the eigenvalues.
Precondition:
The eigenvalues have been computed before.

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.

Example:

Output:

See also:
eigenvectors(), MatrixBase::eigenvalues()

Definition at line 252 of file SelfAdjointEigenSolver.h.

const EigenvectorsType& eigenvectors (  ) const [inherited]

Returns the eigenvectors of given matrix.

Returns:
A const reference to the matrix whose columns are the eigenvectors.
Precondition:
The eigenvectors have been computed before.

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} $.

Example:

Output:

See also:
eigenvalues()

Definition at line 230 of file SelfAdjointEigenSolver.h.

ComputationInfo info (  ) const [inherited]

Reports whether previous computation was successful.

Returns:
Success if computation was succesful, NoConvergence otherwise.

Definition at line 312 of file SelfAdjointEigenSolver.h.

MatrixType operatorInverseSqrt (  ) const [inherited]

Computes the inverse square root of the matrix.

Returns:
the inverse positive-definite square root of the matrix
Precondition:
The eigenvalues and eigenvectors of a positive-definite matrix have been computed before.

This function uses the eigendecomposition $ A = V D V^{-1} $ to compute the inverse square root as $ V D^{-1/2} V^{-1} $. This is cheaper than first computing the square root with operatorSqrt() and then its inverse with MatrixBase::inverse().

Example:

Output:

See also:
operatorSqrt(), MatrixBase::inverse(), MatrixFunctions Module

Definition at line 301 of file SelfAdjointEigenSolver.h.

MatrixType operatorSqrt (  ) const [inherited]

Computes the positive-definite square root of the matrix.

Returns:
the positive-definite square root of the matrix
Precondition:
The eigenvalues and eigenvectors of a positive-definite matrix have been computed before.

The square root of a positive-definite matrix $ A $ is the positive-definite matrix whose square equals $ A $. This function uses the eigendecomposition $ A = V D V^{-1} $ to compute the square root as $ A^{1/2} = V D^{1/2} V^{-1} $.

Example:

Output:

See also:
operatorInverseSqrt(), MatrixFunctions Module

Definition at line 276 of file SelfAdjointEigenSolver.h.


Field Documentation

const int m_maxIterations = 30 [static, inherited]

Maximum number of iterations.

The algorithm terminates if it does not converge within m_maxIterations * n iterations, where n denotes the size of the matrix. This value is currently set to 30 (copied from LAPACK).

Definition at line 323 of file SelfAdjointEigenSolver.h.