![]() |
Eigen
3.4.90 (git rev 9589cc4e7fd8e4538bedef80dd36c7738977a8be)
|
#include <Eigen/src/Eigenvalues/EigenSolver.h>
Computes eigenvalues and eigenvectors of general 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. Currently, only real matrices are supported. |
The eigenvalues and eigenvectors of a matrix
The eigenvalues and eigenvectors of a matrix may be complex, even when the matrix is real. However, we can choose real matrices
(where
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.
Public Types | |
typedef std::complex< RealScalar > | ComplexScalar |
Complex scalar type for MatrixType. | |
typedef Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > | EigenvalueType |
Type for vector of eigenvalues as returned by eigenvalues(). | |
typedef Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > | EigenvectorsType |
Type for matrix of eigenvectors as returned by eigenvectors(). | |
typedef Eigen::Index | Index |
typedef MatrixType_ | MatrixType |
Synonym for the template parameter MatrixType_ . | |
typedef MatrixType::Scalar | Scalar |
Scalar type for matrices of type MatrixType. | |
Public Member Functions | |
template<typename InputType> | |
EigenSolver & | compute (const EigenBase< InputType > &matrix, bool computeEigenvectors=true) |
Computes eigendecomposition of given matrix. | |
EigenSolver () | |
Default constructor. | |
template<typename InputType> | |
EigenSolver (const EigenBase< InputType > &matrix, bool computeEigenvectors=true) | |
Constructor; computes eigendecomposition of given matrix. | |
EigenSolver (Index size) | |
Default constructor with memory preallocation. | |
const EigenvalueType & | eigenvalues () const |
Returns the eigenvalues of given matrix. | |
EigenvectorsType | eigenvectors () const |
Returns the eigenvectors of given matrix. | |
Index | getMaxIterations () |
Returns the maximum number of iterations. | |
ComputationInfo | info () const |
MatrixType | pseudoEigenvalueMatrix () const |
Returns the block-diagonal matrix in the pseudo-eigendecomposition. | |
const MatrixType & | pseudoEigenvectors () const |
Returns the pseudo-eigenvectors of given matrix. | |
EigenSolver & | setMaxIterations (Index maxIters) |
Sets the maximum number of iterations allowed. | |
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.
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.
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.
typedef Eigen::Index Eigen::EigenSolver< MatrixType_ >::Index |
|
inline |
Default constructor.
The default constructor is useful in cases in which the user intends to perform decompositions via EigenSolver::compute(const MatrixType&, bool).
|
inlineexplicit |
Default constructor with memory preallocation.
Like the default constructor but with preallocation of the internal data according to the specified problem size.
|
inlineexplicit |
Constructor; computes eigendecomposition of given matrix.
[in] | matrix | Square matrix whose eigendecomposition is to be computed. |
[in] | computeEigenvectors | If 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:
Here is a random 6x6 matrix, A: 0.696 0.445 0.134 -0.757 -0.778 0.859 0.205 -0.633 -0.16 0.741 -0.758 -0.316 -0.415 0.0241 -0.00986 -0.216 -0.711 0.429 0.334 0.0723 -0.498 0.852 -0.467 -0.0106 -0.47 0.432 -0.727 0.835 0.0072 0.498 0.928 -0.046 0.74 -0.834 0.22 -0.554 The eigenvalues of A are: (-1.65,0) (1.19,0.705) (1.19,-0.705) (0.00732,0.169) (0.00732,-0.169) (-0.38,0) The matrix of eigenvectors, V, is: (0.387,0) (-0.539,0.505) (-0.539,-0.505) (0.0305,-0.138) (0.0305,0.138) (0.112,0) (0.0364,0) (-0.0163,0.163) (-0.0163,-0.163) (0.112,0.413) (0.112,-0.413) (-0.83,0) (0.474,0) (-0.193,-0.107) (-0.193,0.107) (0.574,0.371) (0.574,-0.371) (-0.0453,0) (0.121,0) (0.103,0.373) (0.103,-0.373) (0.347,0.178) (0.347,-0.178) (0.069,0) (0.441,0) (0.315,0.0745) (0.315,-0.0745) (0.114,-0.229) (0.114,0.229) (0.171,0) (-0.644,0) (-0.307,0.174) (-0.307,-0.174) (0.265,-0.206) (0.265,0.206) (0.512,0) Consider the first eigenvalue, lambda = (-1.65,0) If v is the corresponding eigenvector, then lambda * v = (-0.639,0) (-0.0599,0) (-0.781,0) (-0.2,0) (-0.727,0) (1.06,-0) ... and A * v = (-0.639,0) (-0.0599,0) (-0.781,0) (-0.2,0) (-0.727,0) (1.06,0) Finally, V * D * V^(-1) = (0.696,7.37e-17) (0.445,-1.95e-18) (0.134,6.32e-18) (-0.757,1.24e-16) (-0.778,3.25e-16) (0.859,1.05e-16) (0.205,7.93e-17) (-0.633,6.3e-17) (-0.16,-3.92e-17) (0.741,-1.27e-16) (-0.758,9.39e-17) (-0.316,8.01e-17) (-0.415,9.56e-18) (0.0241,1.47e-17) (-0.00986,8.15e-17) (-0.216,-2.32e-17) (-0.711,2.23e-16) (0.429,1e-16) (0.334,1.34e-17) (0.0723,1.25e-16) (-0.498,-4.26e-18) (0.852,-2.91e-16) (-0.467,2.49e-16) (-0.0106,2.19e-16) (-0.47,-6.84e-17) (0.432,1.43e-16) (-0.727,5.78e-17) (0.835,-3.59e-16) (0.0072,2.2e-16) (0.498,2.8e-16) (0.928,8.4e-17) (-0.046,-1.2e-16) (0.74,-6.34e-17) (-0.834,3.74e-16) (0.22,-2.29e-16) (-0.554,-2.57e-16)
EigenSolver & Eigen::EigenSolver< MatrixType_ >::compute | ( | const EigenBase< InputType > & | matrix, |
bool | computeEigenvectors = true ) |
Computes eigendecomposition of given matrix.
[in] | matrix | Square matrix whose eigendecomposition is to be computed. |
[in] | computeEigenvectors | If true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed. |
*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 computeEigenvectors
is true, and computeEigenvectors
is false.
This method reuses of the allocated data in the EigenSolver object.
Example:
Output:
The eigenvalues of A are: (-0.644,0) (0.441,0.322) (0.441,-0.322) (-1.4,0) The eigenvalues of A+I are: (1.44,0.322) (1.44,-0.322) (0.356,0) (-0.397,0)
|
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 not sorted in any particular order.
Example:
Output:
The eigenvalues of the 3x3 matrix of ones are: (-5.31e-17,0) (3,0) (0,0)
EigenSolver< MatrixType >::EigenvectorsType Eigen::EigenSolver< MatrixType >::eigenvectors | ( | ) | const |
Returns the eigenvectors of given matrix.
computeEigenvectors
was set to true (the default).Column
Example:
Output:
The first eigenvector of the 3x3 matrix of ones is: (-0.816,0) (0.408,0) (0.408,0)
|
inline |
MatrixType Eigen::EigenSolver< MatrixType >::pseudoEigenvalueMatrix | ( | ) | const |
Returns the block-diagonal matrix in the pseudo-eigendecomposition.
The matrix
|
inline |
Returns the pseudo-eigenvectors of given matrix.
computeEigenvectors
was set to true (the default).The real matrix
Example:
Output:
Here is a random 6x6 matrix, A: 0.696 0.445 0.134 -0.757 -0.778 0.859 0.205 -0.633 -0.16 0.741 -0.758 -0.316 -0.415 0.0241 -0.00986 -0.216 -0.711 0.429 0.334 0.0723 -0.498 0.852 -0.467 -0.0106 -0.47 0.432 -0.727 0.835 0.0072 0.498 0.928 -0.046 0.74 -0.834 0.22 -0.554 The pseudo-eigenvalue matrix D is: -1.65 0 0 0 0 0 0 1.19 0.705 0 0 0 0 -0.705 1.19 0 0 0 0 0 0 0.00732 0.169 0 0 0 0 -0.169 0.00732 0 0 0 0 0 0 -0.38 The pseudo-eigenvector matrix V is: 0.387 -0.93 0.872 0.0543 -0.245 0.314 0.0364 -0.0282 0.282 0.199 0.735 -2.32 0.474 -0.333 -0.185 1.02 0.661 -0.127 0.121 0.178 0.645 0.618 0.317 0.193 0.441 0.544 0.129 0.203 -0.407 0.477 -0.644 -0.531 0.301 0.471 -0.366 1.43 Finally, V * D * V^(-1) = 0.696 0.445 0.134 -0.757 -0.778 0.859 0.205 -0.633 -0.16 0.741 -0.758 -0.316 -0.415 0.0241 -0.00986 -0.216 -0.711 0.429 0.334 0.0723 -0.498 0.852 -0.467 -0.0106 -0.47 0.432 -0.727 0.835 0.0072 0.498 0.928 -0.046 0.74 -0.834 0.22 -0.554