Computes eigenvalues and eigenvectors of selfadjoint matrices. More...
#include <SelfAdjointEigenSolver.h>
Public Types | |
enum | { Size = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, Options = MatrixType::Options, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime } |
typedef Matrix< Scalar, Size, Size, ColMajor, MaxColsAtCompileTime, MaxColsAtCompileTime > | EigenvectorsType |
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 |
Type for vector of eigenvalues as returned by eigenvalues(). More... | |
typedef MatrixType::Scalar | Scalar |
Scalar type for matrices of type _MatrixType . More... | |
typedef TridiagonalizationType::SubDiagonalType | SubDiagonalType |
typedef Tridiagonalization< MatrixType > | TridiagonalizationType |
Public Member Functions | |
template<typename InputType > | |
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver< MatrixType > & | compute (const EigenBase< InputType > &a_matrix, int options) |
template<typename InputType > | |
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver & | compute (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors) |
Computes eigendecomposition of given matrix. More... | |
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver & | computeDirect (const MatrixType &matrix, int options=ComputeEigenvectors) |
Computes eigendecomposition of given matrix using a closed-form algorithm. More... | |
SelfAdjointEigenSolver & | computeFromTridiagonal (const RealVectorType &diag, const SubDiagonalType &subdiag, int options=ComputeEigenvectors) |
Computes the eigen decomposition from a tridiagonal symmetric matrix. More... | |
const EIGEN_DEVICE_FUNC RealVectorType & | eigenvalues () const |
Returns the eigenvalues of given matrix. More... | |
const EIGEN_DEVICE_FUNC EigenvectorsType & | eigenvectors () const |
Returns the eigenvectors of given matrix. More... | |
EIGEN_DEVICE_FUNC ComputationInfo | info () const |
Reports whether previous computation was successful. More... | |
EIGEN_DEVICE_FUNC MatrixType | operatorInverseSqrt () const |
Computes the inverse square root of the matrix. More... | |
EIGEN_DEVICE_FUNC MatrixType | operatorSqrt () const |
Computes the positive-definite square root of the matrix. More... | |
EIGEN_DEVICE_FUNC | SelfAdjointEigenSolver () |
Default constructor for fixed-size matrices. More... | |
template<typename InputType > | |
EIGEN_DEVICE_FUNC | SelfAdjointEigenSolver (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors) |
Constructor; computes eigendecomposition of given matrix. More... | |
EIGEN_DEVICE_FUNC | SelfAdjointEigenSolver (Index size) |
Constructor, pre-allocates memory for dynamic-size matrices. More... | |
Static Public Attributes | |
static const int | m_maxIterations = 30 |
Maximum number of iterations. More... | |
Static Protected Member Functions | |
static EIGEN_DEVICE_FUNC void | check_template_parameters () |
Friends | |
struct | internal::direct_selfadjoint_eigenvalues< SelfAdjointEigenSolver, Size, NumTraits< Scalar >::IsComplex > |
Computes eigenvalues and eigenvectors of selfadjoint matrices.
\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 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 and vectors such that . The eigenvalues of a selfadjoint matrix are always real. If is a diagonal matrix with the eigenvalues on the diagonal, and is a matrix with the eigenvectors as its columns, then . This is called the eigendecomposition.
For a selfadjoint matrix, is unitary, meaning its inverse is equal to its adjoint, . If is real, then is also real and therefore orthogonal, meaning its inverse is equal to its transpose, .
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 and the likes, see the class GeneralizedSelfAdjointEigenSolver.
Definition at line 76 of file SelfAdjointEigenSolver.h.
typedef Matrix<Scalar,Size,Size,ColMajor,MaxColsAtCompileTime,MaxColsAtCompileTime> Eigen::SelfAdjointEigenSolver< _MatrixType >::EigenvectorsType |
Definition at line 92 of file SelfAdjointEigenSolver.h.
typedef Eigen::Index Eigen::SelfAdjointEigenSolver< _MatrixType >::Index |
Definition at line 90 of file SelfAdjointEigenSolver.h.
typedef _MatrixType Eigen::SelfAdjointEigenSolver< _MatrixType >::MatrixType |
Definition at line 80 of file SelfAdjointEigenSolver.h.
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 100 of file SelfAdjointEigenSolver.h.
typedef internal::plain_col_type<MatrixType, RealScalar>::type Eigen::SelfAdjointEigenSolver< _MatrixType >::RealVectorType |
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 109 of file SelfAdjointEigenSolver.h.
typedef MatrixType::Scalar Eigen::SelfAdjointEigenSolver< _MatrixType >::Scalar |
Scalar type for matrices of type _MatrixType
.
Definition at line 89 of file SelfAdjointEigenSolver.h.
typedef TridiagonalizationType::SubDiagonalType Eigen::SelfAdjointEigenSolver< _MatrixType >::SubDiagonalType |
Definition at line 111 of file SelfAdjointEigenSolver.h.
typedef Tridiagonalization<MatrixType> Eigen::SelfAdjointEigenSolver< _MatrixType >::TridiagonalizationType |
Definition at line 110 of file SelfAdjointEigenSolver.h.
anonymous enum |
Enumerator | |
---|---|
Size | |
ColsAtCompileTime | |
Options | |
MaxColsAtCompileTime |
Definition at line 81 of file SelfAdjointEigenSolver.h.
|
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:
Definition at line 124 of file SelfAdjointEigenSolver.h.
|
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.
Definition at line 147 of file SelfAdjointEigenSolver.h.
|
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:
Definition at line 173 of file SelfAdjointEigenSolver.h.
|
inlinestaticprotected |
Definition at line 376 of file SelfAdjointEigenSolver.h.
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver<MatrixType>& Eigen::SelfAdjointEigenSolver< _MatrixType >::compute | ( | const EigenBase< InputType > & | a_matrix, |
int | options | ||
) |
Definition at line 420 of file SelfAdjointEigenSolver.h.
EIGEN_DEVICE_FUNC 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 if the eigenvectors are required and 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:
EIGEN_DEVICE_FUNC 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:
Definition at line 828 of file SelfAdjointEigenSolver.h.
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.
Definition at line 472 of file SelfAdjointEigenSolver.h.
|
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:
Definition at line 300 of file SelfAdjointEigenSolver.h.
|
inline |
Returns the eigenvectors of given matrix.
Column of the returned matrix is an eigenvector corresponding to eigenvalue number 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 , then the matrix returned by this function is the matrix in the eigendecomposition .
For a selfadjoint matrix, is unitary, meaning its inverse is equal to its adjoint, . If is real, then is also real and therefore orthogonal, meaning its inverse is equal to its transpose, .
Example:
Output:
Definition at line 277 of file SelfAdjointEigenSolver.h.
|
inline |
Reports whether previous computation was successful.
Success
if computation was successful, NoConvergence
otherwise. Definition at line 361 of file SelfAdjointEigenSolver.h.
|
inline |
Computes the inverse square root of the matrix.
This function uses the eigendecomposition to compute the inverse square root as . This is cheaper than first computing the square root with operatorSqrt() and then its inverse with MatrixBase::inverse().
Example:
Output:
Definition at line 349 of file SelfAdjointEigenSolver.h.
|
inline |
Computes the positive-definite square root of the matrix.
The square root of a positive-definite matrix is the positive-definite matrix whose square equals . This function uses the eigendecomposition to compute the square root as .
Example:
Output:
Definition at line 324 of file SelfAdjointEigenSolver.h.
|
friend |
Definition at line 102 of file SelfAdjointEigenSolver.h.
|
protected |
Definition at line 387 of file SelfAdjointEigenSolver.h.
|
protected |
Definition at line 382 of file SelfAdjointEigenSolver.h.
|
protected |
Definition at line 381 of file SelfAdjointEigenSolver.h.
|
protected |
Definition at line 384 of file SelfAdjointEigenSolver.h.
|
protected |
Definition at line 385 of file SelfAdjointEigenSolver.h.
|
protected |
Definition at line 386 of file SelfAdjointEigenSolver.h.
|
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 372 of file SelfAdjointEigenSolver.h.
|
protected |
Definition at line 383 of file SelfAdjointEigenSolver.h.