Eigen::SelfAdjointEigenSolver< MatrixType_ > Class Template Reference

Computes eigenvalues and eigenvectors of selfadjoint matrices. More...

+ Inheritance diagram for Eigen::SelfAdjointEigenSolver< MatrixType_ >:

Public Types

enum  {
  Size ,
  ColsAtCompileTime ,
  Options ,
  MaxColsAtCompileTime
}
 
typedef Matrix< Scalar, Size, Size, ColMajor, MaxColsAtCompileTime, MaxColsAtCompileTimeEigenvectorsType
 
typedef Eigen::Index Index
 
typedef MatrixType_ MatrixType
 
typedef NumTraits< Scalar >::Real RealScalar
 Real scalar type for MatrixType_. More...
 
typedef internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
 
typedef MatrixType::Scalar Scalar
 Scalar type for matrices of type MatrixType_. More...
 
typedef TridiagonalizationType::SubDiagonalType SubDiagonalType
 
typedef Tridiagonalization< MatrixTypeTridiagonalizationType
 
typedef internal::plain_col_type< MatrixType, Scalar >::type VectorType
 Type for vector of eigenvalues as returned by eigenvalues(). More...
 

Public Member Functions

template<typename InputType >
SelfAdjointEigenSolver< MatrixType > & compute (const EigenBase< InputType > &a_matrix, int options)
 
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...
 
 SelfAdjointEigenSolver ()
 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...
 
 SelfAdjointEigenSolver (Index size)
 Constructor, pre-allocates memory for dynamic-size matrices. More...
 

Static Public Attributes

static const int m_maxIterations
 Maximum number of iterations. More...
 

Protected Attributes

bool m_eigenvectorsOk
 
RealVectorType m_eivalues
 
EigenvectorsType m_eivec
 
TridiagonalizationType::CoeffVectorType m_hcoeffs
 
ComputationInfo m_info
 
bool m_isInitialized
 
TridiagonalizationType::SubDiagonalType m_subdiag
 
VectorType m_workspace
 

Detailed Description

template<typename MatrixType_>
class Eigen::SelfAdjointEigenSolver< MatrixType_ >

Computes eigenvalues and eigenvectors of selfadjoint matrices.

This is defined in the Eigenvalues module.

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.

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} \). This is called the eigendecomposition.

For a selfadjoint matrix, \( V \) is unitary, meaning its inverse is equal to its adjoint, \( V^{-1} = V^{\dagger} \). If \( A \) is real, then \( V \) is also real and therefore orthogonal, meaning its inverse is equal to its transpose, \( V^{-1} = V^T \).

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

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.

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

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

See also
MatrixBase::eigenvalues(), class EigenSolver, class ComplexEigenSolver

Definition at line 78 of file SelfAdjointEigenSolver.h.

Member Typedef Documentation

◆ EigenvectorsType

Definition at line 94 of file SelfAdjointEigenSolver.h.

◆ Index

template<typename MatrixType_ >
typedef Eigen::Index Eigen::SelfAdjointEigenSolver< MatrixType_ >::Index
Deprecated:
since Eigen 3.3

Definition at line 92 of file SelfAdjointEigenSolver.h.

◆ MatrixType

template<typename MatrixType_ >
typedef MatrixType_ Eigen::SelfAdjointEigenSolver< MatrixType_ >::MatrixType

Definition at line 82 of file SelfAdjointEigenSolver.h.

◆ RealScalar

template<typename MatrixType_ >
typedef NumTraits<Scalar>::Real Eigen::SelfAdjointEigenSolver< MatrixType_ >::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.

Definition at line 102 of file SelfAdjointEigenSolver.h.

◆ RealVectorType

template<typename MatrixType_ >
typedef internal::plain_col_type<MatrixType, RealScalar>::type Eigen::SelfAdjointEigenSolver< MatrixType_ >::RealVectorType

Definition at line 112 of file SelfAdjointEigenSolver.h.

◆ Scalar

template<typename MatrixType_ >
typedef MatrixType::Scalar Eigen::SelfAdjointEigenSolver< MatrixType_ >::Scalar

Scalar type for matrices of type MatrixType_.

Definition at line 91 of file SelfAdjointEigenSolver.h.

◆ SubDiagonalType

template<typename MatrixType_ >
typedef TridiagonalizationType::SubDiagonalType Eigen::SelfAdjointEigenSolver< MatrixType_ >::SubDiagonalType

Definition at line 114 of file SelfAdjointEigenSolver.h.

◆ TridiagonalizationType

template<typename MatrixType_ >
typedef Tridiagonalization<MatrixType> Eigen::SelfAdjointEigenSolver< MatrixType_ >::TridiagonalizationType

Definition at line 113 of file SelfAdjointEigenSolver.h.

◆ VectorType

template<typename MatrixType_ >
typedef internal::plain_col_type<MatrixType, Scalar>::type Eigen::SelfAdjointEigenSolver< MatrixType_ >::VectorType

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 111 of file SelfAdjointEigenSolver.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename MatrixType_ >
anonymous enum
Enumerator
Size 
ColsAtCompileTime 
Options 
MaxColsAtCompileTime 

Definition at line 83 of file SelfAdjointEigenSolver.h.

83  {
84  Size = MatrixType::RowsAtCompileTime,
85  ColsAtCompileTime = MatrixType::ColsAtCompileTime,
86  Options = MatrixType::Options,
87  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
88  };

Constructor & Destructor Documentation

◆ SelfAdjointEigenSolver() [1/3]

template<typename MatrixType_ >
Eigen::SelfAdjointEigenSolver< MatrixType_ >::SelfAdjointEigenSolver ( )
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 SelfAdjointEigenSolver(Index) for dynamic-size matrices.

Example:

SelfAdjointEigenSolver<Matrix4f> es;
Matrix4f A = X + X.transpose();
es.compute(A);
cout << "The eigenvalues of A are: " << es.eigenvalues().transpose() << endl;
es.compute(A + Matrix4f::Identity(4,4)); // re-use es to compute eigenvalues of A+I
cout << "The eigenvalues of A+I are: " << es.eigenvalues().transpose() << endl;
MatrixXcf A
EigenSolver< MatrixXf > es
static const RandomReturnType Random()
Definition: Random.h:114
static const IdentityReturnType Identity()
Matrix< float, 4, 4 > Matrix4f
4×4 matrix of type float.
Definition: Matrix.h:501

Output:

The eigenvalues of A are:  -1.58 -0.473   1.32   2.46
The eigenvalues of A+I are: -0.581  0.527   2.32   3.46

Definition at line 127 of file SelfAdjointEigenSolver.h.

128  : m_eivec(),
129  m_workspace(),
130  m_eivalues(),
131  m_subdiag(),
132  m_hcoeffs(),
134  m_isInitialized(false),
135  m_eigenvectorsOk(false)
136  { }
TridiagonalizationType::CoeffVectorType m_hcoeffs
TridiagonalizationType::SubDiagonalType m_subdiag
@ InvalidInput
Definition: Constants.h:453

◆ SelfAdjointEigenSolver() [2/3]

template<typename MatrixType_ >
Eigen::SelfAdjointEigenSolver< MatrixType_ >::SelfAdjointEigenSolver ( Index  size)
inlineexplicit

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 151 of file SelfAdjointEigenSolver.h.

152  : m_eivec(size, size),
153  m_workspace(size),
154  m_eivalues(size),
155  m_subdiag(size > 1 ? size - 1 : 1),
156  m_hcoeffs(size > 1 ? size - 1 : 1),
157  m_isInitialized(false),
158  m_eigenvectorsOk(false)
159  {}

◆ SelfAdjointEigenSolver() [3/3]

template<typename MatrixType_ >
template<typename InputType >
Eigen::SelfAdjointEigenSolver< MatrixType_ >::SelfAdjointEigenSolver ( const EigenBase< InputType > &  matrix,
int  options = ComputeEigenvectors 
)
inlineexplicit

Constructor; 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.

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

Example:

MatrixXd A = X + X.transpose();
cout << "Here is a random symmetric 5x5 matrix, A:" << endl << A << endl << endl;
SelfAdjointEigenSolver<MatrixXd> es(A);
cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl;
cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
double lambda = es.eigenvalues()[0];
cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
VectorXd v = es.eigenvectors().col(0);
cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
cout << "... and A * v = " << endl << A * v << endl << endl;
MatrixXd D = es.eigenvalues().asDiagonal();
MatrixXd V = es.eigenvectors();
cout << "Finally, V * D * V^(-1) = " << endl << V * D * V.inverse() << endl;
Array< int, Dynamic, 1 > v
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
Matrix< double, Dynamic, 1 > VectorXd
Dynamic×1 vector of type double.
Definition: Matrix.h:502
Matrix< double, Dynamic, Dynamic > MatrixXd
Dynamic×Dynamic matrix of type double.
Definition: Matrix.h:502

Output:

Here is a random symmetric 5x5 matrix, A:
  1.36 -0.816  0.521   1.43 -0.144
-0.816 -0.659  0.794 -0.173 -0.406
 0.521  0.794 -0.541  0.461  0.179
  1.43 -0.173  0.461  -1.43  0.822
-0.144 -0.406  0.179  0.822  -1.37

The eigenvalues of A are:
 -2.65
 -1.77
-0.745
 0.227
  2.29
The matrix of eigenvectors, V, is:
 -0.326 -0.0984   0.347 -0.0109   0.874
 -0.207  -0.642   0.228   0.662  -0.232
 0.0495   0.629  -0.164    0.74   0.164
  0.721  -0.397  -0.402   0.115   0.385
 -0.573  -0.156  -0.799 -0.0256  0.0858

Consider the first eigenvalue, lambda = -2.65
If v is the corresponding eigenvector, then lambda * v = 
 0.865
  0.55
-0.131
 -1.91
  1.52
... and A * v = 
 0.865
  0.55
-0.131
 -1.91
  1.52

Finally, V * D * V^(-1) = 
  1.36 -0.816  0.521   1.43 -0.144
-0.816 -0.659  0.794 -0.173 -0.406
 0.521  0.794 -0.541  0.461  0.179
  1.43 -0.173  0.461  -1.43  0.822
-0.144 -0.406  0.179  0.822  -1.37
See also
compute(const MatrixType&, int)

Definition at line 178 of file SelfAdjointEigenSolver.h.

179  : m_eivec(matrix.rows(), matrix.cols()),
180  m_workspace(matrix.cols()),
181  m_eivalues(matrix.cols()),
182  m_subdiag(matrix.rows() > 1 ? matrix.rows() - 1 : 1),
183  m_hcoeffs(matrix.cols() > 1 ? matrix.cols() - 1 : 1),
184  m_isInitialized(false),
185  m_eigenvectorsOk(false)
186  {
187  compute(matrix.derived(), options);
188  }
SelfAdjointEigenSolver & compute(const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
Computes eigendecomposition of given matrix.

Member Function Documentation

◆ compute() [1/2]

template<typename MatrixType_ >
template<typename InputType >
SelfAdjointEigenSolver<MatrixType>& Eigen::SelfAdjointEigenSolver< MatrixType_ >::compute ( const EigenBase< InputType > &  a_matrix,
int  options 
)

Definition at line 423 of file SelfAdjointEigenSolver.h.

424 {
425  const InputType &matrix(a_matrix.derived());
426 
428  eigen_assert(matrix.cols() == matrix.rows());
429  eigen_assert((options&~(EigVecMask|GenEigMask))==0
430  && (options&EigVecMask)!=EigVecMask
431  && "invalid option parameter");
432  bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors;
433  Index n = matrix.cols();
434  m_eivalues.resize(n,1);
435 
436  if(n==1)
437  {
438  m_eivec = matrix;
439  m_eivalues.coeffRef(0,0) = numext::real(m_eivec.coeff(0,0));
440  if(computeEigenvectors)
441  m_eivec.setOnes(n,n);
442  m_info = Success;
443  m_isInitialized = true;
444  m_eigenvectorsOk = computeEigenvectors;
445  return *this;
446  }
447 
448  // declare some aliases
449  RealVectorType& diag = m_eivalues;
451 
452  // map the matrix coefficients to [-1:1] to avoid over- and underflow.
453  mat = matrix.template triangularView<Lower>();
454  RealScalar scale = mat.cwiseAbs().maxCoeff();
455  if(numext::is_exactly_zero(scale)) scale = RealScalar(1);
456  mat.template triangularView<Lower>() /= scale;
457  m_subdiag.resize(n-1);
458  m_hcoeffs.resize(n-1);
460 
462 
463  // scale back the eigen values
464  m_eivalues *= scale;
465 
466  m_isInitialized = true;
467  m_eigenvectorsOk = computeEigenvectors;
468  return *this;
469 }
int n
RealReturnType real() const
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1080
#define eigen_assert(x)
Definition: Macros.h:902
constexpr const Scalar & coeff(Index rowId, Index colId) const
Derived & setOnes(Index size)
constexpr void resize(Index rows, Index cols)
internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
NumTraits< Scalar >::Real RealScalar
Real scalar type for MatrixType_.
Matrix< Scalar, Size, Size, ColMajor, MaxColsAtCompileTime, MaxColsAtCompileTime > EigenvectorsType
static const int m_maxIterations
Maximum number of iterations.
@ Success
Definition: Constants.h:446
@ GenEigMask
Definition: Constants.h:420
@ EigVecMask
Definition: Constants.h:409
@ ComputeEigenvectors
Definition: Constants.h:407
ComputationInfo computeFromTridiagonal_impl(DiagType &diag, SubDiagType &subdiag, const Index maxIterations, bool computeEigenvectors, MatrixType &eivec)
void tridiagonalization_inplace(MatrixType &matA, CoeffVectorType &hCoeffs)
bool is_exactly_zero(const X &x)
Definition: Meta.h:475
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)

◆ compute() [2/2]

template<typename MatrixType_ >
template<typename InputType >
SelfAdjointEigenSolver& Eigen::SelfAdjointEigenSolver< MatrixType_ >::compute ( const EigenBase< InputType > &  matrix,
int  options = ComputeEigenvectors 
)

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:

SelfAdjointEigenSolver<MatrixXf> es(4);
MatrixXf A = X + X.transpose();
es.compute(A);
cout << "The eigenvalues of A are: " << es.eigenvalues().transpose() << endl;
es.compute(A + MatrixXf::Identity(4,4)); // re-use es to compute eigenvalues of A+I
cout << "The eigenvalues of A+I are: " << es.eigenvalues().transpose() << endl;
Matrix< float, Dynamic, Dynamic > MatrixXf
Dynamic×Dynamic matrix of type float.
Definition: Matrix.h:501

Output:

The eigenvalues of A are:  -1.58 -0.473   1.32   2.46
The eigenvalues of A+I are: -0.581  0.527   2.32   3.46
See also
SelfAdjointEigenSolver(const MatrixType&, int)

◆ computeDirect()

template<typename MatrixType >
SelfAdjointEigenSolver< MatrixType > & Eigen::SelfAdjointEigenSolver< MatrixType >::computeDirect ( const MatrixType matrix,
int  options = ComputeEigenvectors 
)

Computes eigendecomposition of given matrix using a closed-form algorithm.

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

Currently only 2x2 and 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 iterative 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.

For the 3x3 case, we observed the following worst case relative error regarding the eigenvalues:

  • double: 1e-8
  • float: 1e-3
See also
compute(const MatrixType&, int options)

Definition at line 829 of file SelfAdjointEigenSolver.h.

830 {
831  internal::direct_selfadjoint_eigenvalues<SelfAdjointEigenSolver,Size,NumTraits<Scalar>::IsComplex>::run(*this,matrix,options);
832  return *this;
833 }

◆ computeFromTridiagonal()

template<typename MatrixType >
SelfAdjointEigenSolver< MatrixType > & Eigen::SelfAdjointEigenSolver< MatrixType >::computeFromTridiagonal ( const RealVectorType diag,
const SubDiagonalType subdiag,
int  options = ComputeEigenvectors 
)

Computes the eigen decomposition from a tridiagonal symmetric matrix.

Parameters
[in]diagThe vector containing the diagonal of the matrix.
[in]subdiagThe subdiagonal of the matrix.
[in]optionsCan be ComputeEigenvectors (default) or EigenvaluesOnly.
Returns
Reference to *this

This function assumes that the matrix has been reduced to tridiagonal form.

See also
compute(const MatrixType&, int) for more information

Definition at line 473 of file SelfAdjointEigenSolver.h.

474 {
475  //TODO : Add an option to scale the values beforehand
476  bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors;
477 
478  m_eivalues = diag;
479  m_subdiag = subdiag;
480  if (computeEigenvectors)
481  {
482  m_eivec.setIdentity(diag.size(), diag.size());
483  }
485 
486  m_isInitialized = true;
487  m_eigenvectorsOk = computeEigenvectors;
488  return *this;
489 }

◆ eigenvalues()

template<typename MatrixType_ >
const RealVectorType& Eigen::SelfAdjointEigenSolver< MatrixType_ >::eigenvalues ( ) const
inline

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:

SelfAdjointEigenSolver<MatrixXd> es(ones);
cout << "The eigenvalues of the 3x3 matrix of ones are:"
<< endl << es.eigenvalues() << endl;
static const ConstantReturnType Ones()

Output:

The eigenvalues of the 3x3 matrix of ones are:
-3.09e-16
        0
        3
See also
eigenvectors(), MatrixBase::eigenvalues()

Definition at line 306 of file SelfAdjointEigenSolver.h.

307  {
308  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
309  return m_eivalues;
310  }

◆ eigenvectors()

template<typename MatrixType_ >
const EigenvectorsType& Eigen::SelfAdjointEigenSolver< MatrixType_ >::eigenvectors ( ) const
inline

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} \).

For a selfadjoint matrix, \( V \) is unitary, meaning its inverse is equal to its adjoint, \( V^{-1} = V^{\dagger} \). If \( A \) is real, then \( V \) is also real and therefore orthogonal, meaning its inverse is equal to its transpose, \( V^{-1} = V^T \).

Example:

SelfAdjointEigenSolver<MatrixXd> es(ones);
cout << "The first eigenvector of the 3x3 matrix of ones is:"
<< endl << es.eigenvectors().col(0) << endl;

Output:

The first eigenvector of the 3x3 matrix of ones is:
-0.816
 0.408
 0.408
See also
eigenvalues()

Definition at line 283 of file SelfAdjointEigenSolver.h.

284  {
285  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
286  eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
287  return m_eivec;
288  }

◆ info()

template<typename MatrixType_ >
ComputationInfo Eigen::SelfAdjointEigenSolver< MatrixType_ >::info ( ) const
inline

Reports whether previous computation was successful.

Returns
Success if computation was successful, NoConvergence otherwise.

Definition at line 367 of file SelfAdjointEigenSolver.h.

368  {
369  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
370  return m_info;
371  }

◆ operatorInverseSqrt()

template<typename MatrixType_ >
MatrixType Eigen::SelfAdjointEigenSolver< MatrixType_ >::operatorInverseSqrt ( ) const
inline

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:

MatrixXd A = X * X.transpose();
cout << "Here is a random positive-definite matrix, A:" << endl << A << endl << endl;
SelfAdjointEigenSolver<MatrixXd> es(A);
cout << "The inverse square root of A is: " << endl;
cout << es.operatorInverseSqrt() << endl;
cout << "We can also compute it with operatorSqrt() and inverse(). That yields: " << endl;
cout << es.operatorSqrt().inverse() << endl;

Output:

Here is a random positive-definite matrix, A:
  1.41 -0.697 -0.111  0.508
-0.697  0.423 0.0991   -0.4
-0.111 0.0991   1.25  0.902
 0.508   -0.4  0.902    1.4

The inverse square root of A is: 
  1.88   2.78 -0.546  0.605
  2.78   8.61   -2.3   2.74
-0.546   -2.3   1.92  -1.36
 0.605   2.74  -1.36   2.18
We can also compute it with operatorSqrt() and inverse(). That yields: 
  1.88   2.78 -0.546  0.605
  2.78   8.61   -2.3   2.74
-0.546   -2.3   1.92  -1.36
 0.605   2.74  -1.36   2.18
See also
operatorSqrt(), MatrixBase::inverse(), MatrixFunctions Module

Definition at line 355 of file SelfAdjointEigenSolver.h.

356  {
357  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
358  eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
359  return m_eivec * m_eivalues.cwiseInverse().cwiseSqrt().asDiagonal() * m_eivec.adjoint();
360  }

◆ operatorSqrt()

template<typename MatrixType_ >
MatrixType Eigen::SelfAdjointEigenSolver< MatrixType_ >::operatorSqrt ( ) const
inline

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:

MatrixXd A = X * X.transpose();
cout << "Here is a random positive-definite matrix, A:" << endl << A << endl << endl;
SelfAdjointEigenSolver<MatrixXd> es(A);
MatrixXd sqrtA = es.operatorSqrt();
cout << "The square root of A is: " << endl << sqrtA << endl;
cout << "If we square this, we get: " << endl << sqrtA*sqrtA << endl;

Output:

Here is a random positive-definite matrix, A:
  1.41 -0.697 -0.111  0.508
-0.697  0.423 0.0991   -0.4
-0.111 0.0991   1.25  0.902
 0.508   -0.4  0.902    1.4

The square root of A is: 
   1.09  -0.432 -0.0685     0.2
 -0.432   0.379   0.141  -0.269
-0.0685   0.141       1   0.468
    0.2  -0.269   0.468    1.04
If we square this, we get: 
  1.41 -0.697 -0.111  0.508
-0.697  0.423 0.0991   -0.4
-0.111 0.0991   1.25  0.902
 0.508   -0.4  0.902    1.4
See also
operatorInverseSqrt(), MatrixFunctions Module

Definition at line 330 of file SelfAdjointEigenSolver.h.

331  {
332  eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
333  eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
334  return m_eivec * m_eivalues.cwiseSqrt().asDiagonal() * m_eivec.adjoint();
335  }

Member Data Documentation

◆ m_eigenvectorsOk

template<typename MatrixType_ >
bool Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eigenvectorsOk
protected

Definition at line 390 of file SelfAdjointEigenSolver.h.

◆ m_eivalues

template<typename MatrixType_ >
RealVectorType Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivalues
protected

Definition at line 385 of file SelfAdjointEigenSolver.h.

◆ m_eivec

template<typename MatrixType_ >
EigenvectorsType Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_eivec
protected

Definition at line 383 of file SelfAdjointEigenSolver.h.

◆ m_hcoeffs

template<typename MatrixType_ >
TridiagonalizationType::CoeffVectorType Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_hcoeffs
protected

Definition at line 387 of file SelfAdjointEigenSolver.h.

◆ m_info

template<typename MatrixType_ >
ComputationInfo Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_info
protected

Definition at line 388 of file SelfAdjointEigenSolver.h.

◆ m_isInitialized

template<typename MatrixType_ >
bool Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_isInitialized
protected

Definition at line 389 of file SelfAdjointEigenSolver.h.

◆ m_maxIterations

template<typename MatrixType_ >
const int Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_maxIterations
static

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 378 of file SelfAdjointEigenSolver.h.

◆ m_subdiag

template<typename MatrixType_ >
TridiagonalizationType::SubDiagonalType Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_subdiag
protected

Definition at line 386 of file SelfAdjointEigenSolver.h.

◆ m_workspace

template<typename MatrixType_ >
VectorType Eigen::SelfAdjointEigenSolver< MatrixType_ >::m_workspace
protected

Definition at line 384 of file SelfAdjointEigenSolver.h.


The documentation for this class was generated from the following file: