![]() |
Eigen
3.4.90 (git rev 9589cc4e7fd8e4538bedef80dd36c7738977a8be)
|
#include <Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h>
Computes eigenvalues and eigenvectors of selfadjoint matrices.
This is defined in the Eigenvalues module.
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
For a selfadjoint matrix,
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
Public Types | |
typedef Eigen::Index | Index |
typedef NumTraits< Scalar >::Real | RealScalar |
Real scalar type for MatrixType_ . | |
typedef MatrixType::Scalar | Scalar |
Scalar type for matrices of type MatrixType_ . | |
typedef internal::plain_col_type< MatrixType, Scalar >::type | VectorType |
Type for vector of eigenvalues as returned by eigenvalues(). | |
Public Member Functions | |
template<typename InputType> | |
SelfAdjointEigenSolver & | compute (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors) |
Computes eigendecomposition of given matrix. | |
SelfAdjointEigenSolver & | computeDirect (const MatrixType &matrix, int options=ComputeEigenvectors) |
Computes eigendecomposition of given matrix using a closed-form algorithm. | |
SelfAdjointEigenSolver & | computeFromTridiagonal (const RealVectorType &diag, const SubDiagonalType &subdiag, int options=ComputeEigenvectors) |
Computes the eigen decomposition from a tridiagonal symmetric matrix. | |
const RealVectorType & | eigenvalues () const |
Returns the eigenvalues of given matrix. | |
const EigenvectorsType & | eigenvectors () const |
Returns the eigenvectors of given matrix. | |
ComputationInfo | info () const |
Reports whether previous computation was successful. | |
MatrixType | operatorInverseSqrt () const |
Computes the inverse square root of the matrix. | |
MatrixType | operatorSqrt () const |
Computes the positive-definite square root of the matrix. | |
SelfAdjointEigenSolver () | |
Default constructor for fixed-size matrices. | |
template<typename InputType> | |
SelfAdjointEigenSolver (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors) | |
Constructor; computes eigendecomposition of given matrix. | |
SelfAdjointEigenSolver (Index size) | |
Constructor, pre-allocates memory for dynamic-size matrices. | |
Static Public Attributes | |
static const int | m_maxIterations |
Maximum number of iterations. | |
typedef Eigen::Index Eigen::SelfAdjointEigenSolver< MatrixType_ >::Index |
typedef NumTraits<Scalar>::Real Eigen::SelfAdjointEigenSolver< MatrixType_ >::RealScalar |
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_
.
|
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:
Output:
The eigenvalues of A are: -2.99 -1.55 0.409 1.81 The eigenvalues of A+I are: -1.99 -0.547 1.41 2.81
|
inlineexplicit |
Constructor, pre-allocates memory for dynamic-size matrices.
[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.
|
inlineexplicit |
Constructor; computes eigendecomposition of given matrix.
[in] | matrix | Selfadjoint matrix whose eigendecomposition is to be computed. Only the lower triangular part of the matrix is referenced. |
[in] | options | Can 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:
Output:
Here is a random symmetric 5x5 matrix, A: 1.39 1.13 0.0173 -0.164 -0.686 1.13 0.89 -0.679 -0.703 0.925 0.0173 -0.679 0.268 0.581 0.825 -0.164 -0.703 0.581 -1.51 -0.0932 -0.686 0.925 0.825 -0.0932 -1.56 The eigenvalues of A are: -2.53 -1.78 0.488 0.792 2.51 The matrix of eigenvectors, V, is: -0.253 -0.0404 0.165 -0.653 0.693 0.363 0.234 -0.451 0.425 0.655 0.346 -0.179 -0.692 -0.557 -0.243 -0.0634 0.954 -0.0307 -0.23 -0.177 -0.825 -0.0331 -0.538 0.172 -0.0133 Consider the first eigenvalue, lambda = -2.53 If v is the corresponding eigenvector, then lambda * v = 0.64 -0.917 -0.875 0.16 2.08 ... and A * v = 0.64 -0.917 -0.875 0.16 2.08 Finally, V * D * V^(-1) = 1.39 1.13 0.0173 -0.164 -0.686 1.13 0.89 -0.679 -0.703 0.925 0.0173 -0.679 0.268 0.581 0.825 -0.164 -0.703 0.581 -1.51 -0.0932 -0.686 0.925 0.825 -0.0932 -1.56
SelfAdjointEigenSolver & Eigen::SelfAdjointEigenSolver< MatrixType_ >::compute | ( | const EigenBase< InputType > & | matrix, |
int | options = ComputeEigenvectors ) |
Computes eigendecomposition of given matrix.
[in] | matrix | Selfadjoint matrix whose eigendecomposition is to be computed. Only the lower triangular part of the matrix is referenced. |
[in] | options | Can be ComputeEigenvectors (default) or EigenvaluesOnly. |
*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
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:
The eigenvalues of A are: -2.99 -1.55 0.409 1.81 The eigenvalues of A+I are: -1.99 -0.547 1.41 2.81
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:
SelfAdjointEigenSolver< MatrixType > & Eigen::SelfAdjointEigenSolver< MatrixType >::computeFromTridiagonal | ( | const RealVectorType & | diag, |
const SubDiagonalType & | subdiag, | ||
int | options = ComputeEigenvectors ) |
Computes the eigen decomposition from a tridiagonal symmetric matrix.
[in] | diag | The vector containing the diagonal of the matrix. |
[in] | subdiag | The subdiagonal of the matrix. |
[in] | options | Can be ComputeEigenvectors (default) or EigenvaluesOnly. |
*this
This function assumes that the matrix has been reduced to tridiagonal form.
|
inline |
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.
Example:
Output:
The eigenvalues of the 3x3 matrix of ones are: -3.09e-16 0 3
|
inline |
Returns the eigenvectors of given matrix.
Column
For a selfadjoint matrix,
Example:
Output:
The first eigenvector of the 3x3 matrix of ones is: -0.816 0.408 0.408
|
inline |
Reports whether previous computation was successful.
Success
if computation was successful, NoConvergence
otherwise.
|
inline |
Computes the inverse square root of the matrix.
This function uses the eigendecomposition
Example:
Output:
Here is a random positive-definite matrix, A: 0.724 -0.312 -0.489 0.462 -0.312 0.933 0.361 -0.442 -0.489 0.361 0.557 -0.435 0.462 -0.442 -0.435 0.762 The inverse square root of A is: 1.73 0.0201 0.719 -0.31 0.0201 1.2 -0.238 0.263 0.719 -0.238 2.18 0.364 -0.31 0.263 0.364 1.57 We can also compute it with operatorSqrt() and inverse(). That yields: 1.73 0.0201 0.719 -0.31 0.0201 1.2 -0.238 0.263 0.719 -0.238 2.18 0.364 -0.31 0.263 0.364 1.57
|
inline |
Computes the positive-definite square root of the matrix.
The square root of a positive-definite matrix
Example:
Output:
Here is a random positive-definite matrix, A: 0.724 -0.312 -0.489 0.462 -0.312 0.933 0.361 -0.442 -0.489 0.361 0.557 -0.435 0.462 -0.442 -0.435 0.762 The square root of A is: 0.749 -0.124 -0.301 0.239 -0.124 0.916 0.178 -0.219 -0.301 0.178 0.617 -0.233 0.239 -0.219 -0.233 0.776 If we square this, we get: 0.724 -0.312 -0.489 0.462 -0.312 0.933 0.361 -0.442 -0.489 0.361 0.557 -0.435 0.462 -0.442 -0.435 0.762
|
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).