WPILibC++ 2023.4.3
Eigen::EigenSolver< _MatrixType > Class Template Reference

\eigenvalues_module More...

#include </home/runner/work/allwpilib/allwpilib/wpimath/src/main/native/thirdparty/eigen/include/Eigen/src/Eigenvalues/EigenSolver.h>

Public Types

enum  {
  RowsAtCompileTime = MatrixType::RowsAtCompileTime , ColsAtCompileTime = MatrixType::ColsAtCompileTime , Options = MatrixType::Options , MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime ,
  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
}
 
typedef _MatrixType MatrixType
 Synonym for the template parameter _MatrixType. More...
 
typedef MatrixType::Scalar Scalar
 Scalar type for matrices of type MatrixType. More...
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef Eigen::Index Index
 
typedef std::complex< RealScalarComplexScalar
 Complex scalar type for MatrixType. More...
 
typedef Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > EigenvalueType
 Type for vector of eigenvalues as returned by eigenvalues(). More...
 
typedef Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTimeEigenvectorsType
 Type for matrix of eigenvectors as returned by eigenvectors(). More...
 

Public Member Functions

 EigenSolver ()
 Default constructor. More...
 
 EigenSolver (Index size)
 Default constructor with memory preallocation. More...
 
template<typename InputType >
 EigenSolver (const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
 Constructor; computes eigendecomposition of given matrix. More...
 
EigenvectorsType eigenvectors () const
 Returns the eigenvectors of given matrix. More...
 
const MatrixTypepseudoEigenvectors () const
 Returns the pseudo-eigenvectors of given matrix. More...
 
MatrixType pseudoEigenvalueMatrix () const
 Returns the block-diagonal matrix in the pseudo-eigendecomposition. More...
 
const EigenvalueTypeeigenvalues () const
 Returns the eigenvalues of given matrix. More...
 
template<typename InputType >
EigenSolvercompute (const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
 Computes eigendecomposition of given matrix. More...
 
ComputationInfo info () const
 
EigenSolversetMaxIterations (Index maxIters)
 Sets the maximum number of iterations allowed. More...
 
Index getMaxIterations ()
 Returns the maximum number of iterations. More...
 
template<typename InputType >
EigenSolver< MatrixType > & compute (const EigenBase< InputType > &matrix, bool computeEigenvectors)
 

Protected Types

typedef Matrix< Scalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > ColumnVectorType
 

Static Protected Member Functions

static void check_template_parameters ()
 

Protected Attributes

MatrixType m_eivec
 
EigenvalueType m_eivalues
 
bool m_isInitialized
 
bool m_eigenvectorsOk
 
ComputationInfo m_info
 
RealSchur< MatrixTypem_realSchur
 
MatrixType m_matT
 
ColumnVectorType m_tmp
 

Detailed Description

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

\eigenvalues_module

Computes eigenvalues and eigenvectors of general matrices

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. Currently, only real matrices are supported.

The eigenvalues and eigenvectors of a matrix \( A \) are scalars \( \lambda \) and vectors \( v \) such that \( Av = \lambda v \). 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 = V D \). The matrix \( V \) is almost always invertible, in which case we have \( A = V D V^{-1} \). This is called the eigendecomposition.

The eigenvalues and eigenvectors of a matrix may be complex, even when the matrix is real. However, we can choose real matrices \( V \) and \( D \) satisfying \( A V = V D \), just like the eigendecomposition, if the matrix \( D \) is not required to be diagonal, but if it is allowed to have blocks of the form

\[ \begin{bmatrix} u & v \\ -v & u \end{bmatrix} \]

(where \( u \) and \( v \) are real numbers) on the diagonal. These blocks correspond to complex eigenvalue pairs \( u \pm iv \). We call this variant of the eigendecomposition the pseudo-eigendecomposition.

Call the function compute() to compute the eigenvalues and eigenvectors of a given matrix. Alternatively, you can use the EigenSolver(const MatrixType&, bool) 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 pseudoEigenvalueMatrix() and pseudoEigenvectors() methods allow the construction of the pseudo-eigendecomposition.

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

Note
The implementation is adapted from JAMA (public domain). Their code is based on EISPACK.
See also
MatrixBase::eigenvalues(), class ComplexEigenSolver, class SelfAdjointEigenSolver

Member Typedef Documentation

◆ ColumnVectorType

template<typename _MatrixType >
typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> Eigen::EigenSolver< _MatrixType >::ColumnVectorType
protected

◆ ComplexScalar

template<typename _MatrixType >
typedef std::complex<RealScalar> Eigen::EigenSolver< _MatrixType >::ComplexScalar

Complex scalar type for MatrixType.

This is std::complex<Scalar> if Scalar is real (e.g., float or double) and just Scalar if Scalar is complex.

◆ EigenvalueType

template<typename _MatrixType >
typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> Eigen::EigenSolver< _MatrixType >::EigenvalueType

Type for vector of eigenvalues as returned by eigenvalues().

This is a column vector with entries of type ComplexScalar. The length of the vector is the size of MatrixType.

◆ EigenvectorsType

template<typename _MatrixType >
typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> Eigen::EigenSolver< _MatrixType >::EigenvectorsType

Type for matrix of eigenvectors as returned by eigenvectors().

This is a square matrix with entries of type ComplexScalar. The size is the same as the size of MatrixType.

◆ Index

template<typename _MatrixType >
typedef Eigen::Index Eigen::EigenSolver< _MatrixType >::Index
Deprecated:
since Eigen 3.3

◆ MatrixType

template<typename _MatrixType >
typedef _MatrixType Eigen::EigenSolver< _MatrixType >::MatrixType

Synonym for the template parameter _MatrixType.

◆ RealScalar

template<typename _MatrixType >
typedef NumTraits<Scalar>::Real Eigen::EigenSolver< _MatrixType >::RealScalar

◆ Scalar

template<typename _MatrixType >
typedef MatrixType::Scalar Eigen::EigenSolver< _MatrixType >::Scalar

Scalar type for matrices of type MatrixType.

Member Enumeration Documentation

◆ anonymous enum

template<typename _MatrixType >
anonymous enum
Enumerator
RowsAtCompileTime 
ColsAtCompileTime 
Options 
MaxRowsAtCompileTime 
MaxColsAtCompileTime 

Constructor & Destructor Documentation

◆ EigenSolver() [1/3]

template<typename _MatrixType >
Eigen::EigenSolver< _MatrixType >::EigenSolver ( )
inline

Default constructor.

The default constructor is useful in cases in which the user intends to perform decompositions via EigenSolver::compute(const MatrixType&, bool).

See also
compute() for an example.

◆ EigenSolver() [2/3]

template<typename _MatrixType >
Eigen::EigenSolver< _MatrixType >::EigenSolver ( Index  size)
inlineexplicit

Default constructor with memory preallocation.

Like the default constructor but with preallocation of the internal data according to the specified problem size.

See also
EigenSolver()

◆ EigenSolver() [3/3]

template<typename _MatrixType >
template<typename InputType >
Eigen::EigenSolver< _MatrixType >::EigenSolver ( const EigenBase< InputType > &  matrix,
bool  computeEigenvectors = true 
)
inlineexplicit

Constructor; computes eigendecomposition of given matrix.

Parameters
[in]matrixSquare matrix whose eigendecomposition is to be computed.
[in]computeEigenvectorsIf true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed.

This constructor calls compute() to compute the eigenvalues and eigenvectors.

Example:

Output:

See also
compute()

Member Function Documentation

◆ check_template_parameters()

template<typename _MatrixType >
static void Eigen::EigenSolver< _MatrixType >::check_template_parameters ( )
inlinestaticprotected

◆ compute() [1/2]

template<typename _MatrixType >
template<typename InputType >
EigenSolver< MatrixType > & Eigen::EigenSolver< _MatrixType >::compute ( const EigenBase< InputType > &  matrix,
bool  computeEigenvectors 
)

◆ compute() [2/2]

template<typename _MatrixType >
template<typename InputType >
EigenSolver & Eigen::EigenSolver< _MatrixType >::compute ( const EigenBase< InputType > &  matrix,
bool  computeEigenvectors = true 
)

Computes eigendecomposition of given matrix.

Parameters
[in]matrixSquare matrix whose eigendecomposition is to be computed.
[in]computeEigenvectorsIf true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed.
Returns
Reference to *this

This function computes the eigenvalues of the real matrix matrix. The eigenvalues() function can be used to retrieve them. If computeEigenvectors is true, then the eigenvectors are also computed and can be retrieved by calling eigenvectors().

The matrix is first reduced to real Schur form using the RealSchur class. The Schur decomposition is then used to compute the eigenvalues and eigenvectors.

The cost of the computation is dominated by the cost of the Schur decomposition, which is very approximately \( 25n^3 \) (where \( n \) is the size of the matrix) if computeEigenvectors is true, and \( 10n^3 \) if computeEigenvectors is false.

This method reuses of the allocated data in the EigenSolver object.

Example:

Output:

 

◆ eigenvalues()

template<typename _MatrixType >
const EigenvalueType & Eigen::EigenSolver< _MatrixType >::eigenvalues ( ) const
inline

Returns the eigenvalues of given matrix.

Returns
A const reference to the column vector containing the eigenvalues.
Precondition
Either the constructor EigenSolver(const MatrixType&,bool) or the member function compute(const MatrixType&, bool) has been called before.

The eigenvalues are repeated according to their algebraic multiplicity, so there are as many eigenvalues as rows in the matrix. The eigenvalues are not sorted in any particular order.

Example:

Output:

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

◆ eigenvectors()

Returns the eigenvectors of given matrix.

Returns
Matrix whose columns are the (possibly complex) eigenvectors.
Precondition
Either the constructor EigenSolver(const MatrixType&,bool) or the member function compute(const MatrixType&, bool) has been called before, and computeEigenvectors was set to true (the default).

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. The matrix returned by this function is the matrix \( V \) in the eigendecomposition \( A = V D V^{-1} \), if it exists.

Example:

Output:

See also
eigenvalues(), pseudoEigenvectors()

◆ getMaxIterations()

template<typename _MatrixType >
Index Eigen::EigenSolver< _MatrixType >::getMaxIterations ( )
inline

Returns the maximum number of iterations.

◆ info()

template<typename _MatrixType >
ComputationInfo Eigen::EigenSolver< _MatrixType >::info ( ) const
inline
Returns
NumericalIssue if the input contains INF or NaN values or overflow occurred. Returns Success otherwise.

◆ pseudoEigenvalueMatrix()

template<typename MatrixType >
MatrixType Eigen::EigenSolver< MatrixType >::pseudoEigenvalueMatrix

Returns the block-diagonal matrix in the pseudo-eigendecomposition.

Returns
A block-diagonal matrix.
Precondition
Either the constructor EigenSolver(const MatrixType&,bool) or the member function compute(const MatrixType&, bool) has been called before.

The matrix \( D \) returned by this function is real and block-diagonal. The blocks on the diagonal are either 1-by-1 or 2-by-2 blocks of the form \( \begin{bmatrix} u & v \\ -v & u \end{bmatrix} \). These blocks are not sorted in any particular order. The matrix \( D \) and the matrix \( V \) returned by pseudoEigenvectors() satisfy \( AV = VD \).

See also
pseudoEigenvectors() for an example, eigenvalues()

◆ pseudoEigenvectors()

template<typename _MatrixType >
const MatrixType & Eigen::EigenSolver< _MatrixType >::pseudoEigenvectors ( ) const
inline

Returns the pseudo-eigenvectors of given matrix.

Returns
Const reference to matrix whose columns are the pseudo-eigenvectors.
Precondition
Either the constructor EigenSolver(const MatrixType&,bool) or the member function compute(const MatrixType&, bool) has been called before, and computeEigenvectors was set to true (the default).

The real matrix \( V \) returned by this function and the block-diagonal matrix \( D \) returned by pseudoEigenvalueMatrix() satisfy \( AV = VD \).

Example:

Output:

See also
pseudoEigenvalueMatrix(), eigenvectors()

◆ setMaxIterations()

template<typename _MatrixType >
EigenSolver & Eigen::EigenSolver< _MatrixType >::setMaxIterations ( Index  maxIters)
inline

Sets the maximum number of iterations allowed.

Member Data Documentation

◆ m_eigenvectorsOk

template<typename _MatrixType >
bool Eigen::EigenSolver< _MatrixType >::m_eigenvectorsOk
protected

◆ m_eivalues

template<typename _MatrixType >
EigenvalueType Eigen::EigenSolver< _MatrixType >::m_eivalues
protected

◆ m_eivec

template<typename _MatrixType >
MatrixType Eigen::EigenSolver< _MatrixType >::m_eivec
protected

◆ m_info

template<typename _MatrixType >
ComputationInfo Eigen::EigenSolver< _MatrixType >::m_info
protected

◆ m_isInitialized

template<typename _MatrixType >
bool Eigen::EigenSolver< _MatrixType >::m_isInitialized
protected

◆ m_matT

template<typename _MatrixType >
MatrixType Eigen::EigenSolver< _MatrixType >::m_matT
protected

◆ m_realSchur

template<typename _MatrixType >
RealSchur<MatrixType> Eigen::EigenSolver< _MatrixType >::m_realSchur
protected

◆ m_tmp

template<typename _MatrixType >
ColumnVectorType Eigen::EigenSolver< _MatrixType >::m_tmp
protected

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