 Eigen  3.4.90 (git rev a4098ac676528a83cfb73d4d26ce1b42ec05f47c) Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ > Class Template Reference

## Detailed Description

template<typename MatrixType_>

Computes eigenvalues and eigenvectors of the generalized selfadjoint eigen problem.

This is defined in the Eigenvalues module.

#include <Eigen/Eigenvalues>
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.

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.

class SelfAdjointEigenSolver, class EigenSolver, class ComplexEigenSolver Inheritance diagram for Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >:

## Public Member Functions

GeneralizedSelfAdjointEigenSolvercompute (const MatrixType &matA, const MatrixType &matB, int options=ComputeEigenvectors|Ax_lBx)
Computes generalized eigendecomposition of given matrix pencil. More...

Default constructor for fixed-size matrices. More...

GeneralizedSelfAdjointEigenSolver (const MatrixType &matA, const MatrixType &matB, int options=ComputeEigenvectors|Ax_lBx)
Constructor; computes generalized eigendecomposition of given matrix pencil. More...

Constructor, pre-allocates memory for dynamic-size matrices. More... Public Member Functions inherited from Eigen::SelfAdjointEigenSolver< MatrixType_ >
template<typename InputType >
SelfAdjointEigenSolvercompute (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
Computes eigendecomposition of given matrix. More...

SelfAdjointEigenSolvercomputeDirect (const MatrixType &matrix, int options=ComputeEigenvectors)
Computes eigendecomposition of given matrix using a closed-form algorithm. More...

SelfAdjointEigenSolvercomputeFromTridiagonal (const RealVectorType &diag, const SubDiagonalType &subdiag, int options=ComputeEigenvectors)
Computes the eigen decomposition from a tridiagonal symmetric matrix. More...

const RealVectorTypeeigenvalues () const
Returns the eigenvalues of given matrix. More...

const EigenvectorsTypeeigenvectors () const
Returns the eigenvectors of given matrix. More...

ComputationInfo info () const
Reports whether previous computation was successful. More...

MatrixType operatorInverseSqrt () const
Computes the inverse square root of the matrix. More...

MatrixType operatorSqrt () const
Computes the positive-definite square root of the matrix. More...

Default constructor for fixed-size matrices. More...

template<typename InputType >
SelfAdjointEigenSolver (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
Constructor; computes eigendecomposition of given matrix. More...

Constructor, pre-allocates memory for dynamic-size matrices. More... Public Types inherited from Eigen::SelfAdjointEigenSolver< MatrixType_ >
typedef Eigen::Index Index

typedef NumTraits< Scalar >::Real RealScalar
Real scalar type for MatrixType_. More...

typedef internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
Type for vector of eigenvalues as returned by eigenvalues(). More...

typedef MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType_. Static Public Attributes inherited from Eigen::SelfAdjointEigenSolver< MatrixType_ >
static const int m_maxIterations
Maximum number of iterations. More...

## Constructor & Destructor Documentation

template<typename MatrixType_ >
inline

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.

template<typename MatrixType_ >
inlineexplicit

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

Parameters
 [in] size Positive 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.

compute() for an example

template<typename MatrixType_ >
 Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >::GeneralizedSelfAdjointEigenSolver ( const MatrixType & matA, const MatrixType & matB, int options = ComputeEigenvectors|Ax_lBx )
inline

Constructor; computes generalized eigendecomposition of given matrix pencil.

Parameters
 [in] matA Selfadjoint matrix in matrix pencil. Only the lower triangular part of the matrix is referenced. [in] matB Positive-definite matrix in matrix pencil. Only the lower triangular part of the matrix is referenced. [in] options A 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:

MatrixXd X = MatrixXd::Random(5,5);
MatrixXd A = X + X.transpose();
cout << "Here is a random symmetric matrix, A:" << endl << A << endl;
MatrixXd B = X * X.transpose();
cout << "and a random positive-definite matrix, B:" << endl << B << endl << endl;
cout << "The eigenvalues of the pencil (A,B) are:" << endl << es.eigenvalues() << endl;
cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
double lambda = es.eigenvalues();
cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
VectorXd v = es.eigenvectors().col(0);
cout << "If v is the corresponding eigenvector, then A * v = " << endl << A * v << endl;
cout << "... and lambda * B * v = " << endl << lambda * B * v << endl << endl;
static const RandomReturnType Random()
Definition: Random.h:115

Output:

Here is a random symmetric matrix, A:
-2     -1.3    0.278  -0.0233  -0.0995
-1.3    -1.81    0.397    0.701     1.24
0.278    0.397     1.32    -1.92   -0.715
-0.0233    0.701    -1.92   -0.466 -0.00544
-0.0995     1.24   -0.715 -0.00544     1.38
and a random positive-definite matrix, B:
1.78 -0.418  -1.43 -0.957  0.457
-0.418   2.01  0.268  0.292  0.107
-1.43  0.268   1.37  0.758 -0.201
-0.957  0.292  0.758   2.28 -0.548
0.457  0.107 -0.201 -0.548  0.565

The eigenvalues of the pencil (A,B) are:
-5.66
-2.3
-0.174
1.72
15
The matrix of eigenvectors, V, is:
1.77 -0.178  -0.26 0.0956  -1.87
0.402  0.581  0.289  0.156 -0.114
1.27 -0.441  0.148  0.644  -2.23
0.365 -0.442  0.263 -0.235  0.492
-0.361 -0.661 -0.156  0.915   1.68

Consider the first eigenvalue, lambda = -5.66
If v is the corresponding eigenvector, then A * v =
-3.68
-2.71
1.89
-2.35
-1.08
... and lambda * B * v =
-3.68
-2.71
1.89
-2.35
-1.08


compute(const MatrixType&, const MatrixType&, int)

## ◆ compute()

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

Computes generalized eigendecomposition of given matrix pencil.

Parameters
 [in] matA Selfadjoint matrix in matrix pencil. Only the lower triangular part of the matrix is referenced. [in] matB Positive-definite matrix in matrix pencil. Only the lower triangular part of the matrix is referenced. [in] options A or-ed set of flags {ComputeEigenvectors,EigenvaluesOnly} | {Ax_lBx,ABx_lx,BAx_lx}. Default is ComputeEigenvectors|Ax_lBx.
Returns
Reference to *this

According 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:

MatrixXd X = MatrixXd::Random(5,5);
MatrixXd A = X * X.transpose();
MatrixXd B = X * X.transpose();
cout << "The eigenvalues of the pencil (A,B) are:" << endl << es.eigenvalues() << endl;
es.compute(B,A,false);
cout << "The eigenvalues of the pencil (B,A) are:" << endl << es.eigenvalues() << endl;
@ EigenvaluesOnly
Definition: Constants.h:404

Output:

The eigenvalues of the pencil (A,B) are:
0.000125
0.126
2.06
4.84
20.8
The eigenvalues of the pencil (B,A) are:
0.0481
0.207
0.485
7.97
8e+03