template<typename _MatrixType>
GeneralizedEigenSolver class
Computes the generalized eigenvalues and eigenvectors of a pair of general matrices.
Template parameters | |
---|---|
_MatrixType | the type of the matrices of which we are computing the eigen-decomposition; this is expected to be an instantiation of the Matrix class template. Currently, only real matrices are supported. |
Contents
This is defined in the Eigenvalues module. #include <Eigen/Eigenvalues>
The generalized eigenvalues and eigenvectors of a matrix pair and are scalars and vectors such that . If is a diagonal matrix with the eigenvalues on the diagonal, and is a matrix with the eigenvectors as its columns, then . The matrix is almost always invertible, in which case we have . This is called the generalized eigen-decomposition.
The generalized eigenvalues and eigenvectors of a matrix pair may be complex, even when the matrices are real. Moreover, the generalized eigenvalue might be infinite if the matrix B is singular. To workaround this difficulty, the eigenvalues are provided as a pair of complex and real such that: . If is (nearly) zero, then one can consider the well defined left eigenvalue such that: , or even where is called the left eigenvector.
Call the function compute() to compute the generalized eigenvalues and eigenvectors of a given matrix pair. Alternatively, you can use the GeneralizedEigenSolver(const MatrixType&, 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.
Here is an usage example of this class: Example:
GeneralizedEigenSolver<MatrixXf> ges; MatrixXf A = MatrixXf::Random(4,4); MatrixXf B = MatrixXf::Random(4,4); ges.compute(A, B); cout << "The (complex) numerators of the generalzied eigenvalues are: " << ges.alphas().transpose() << endl; cout << "The (real) denominatore of the generalzied eigenvalues are: " << ges.betas().transpose() << endl; cout << "The (complex) generalzied eigenvalues are (alphas./beta): " << ges.eigenvalues().transpose() << endl;
Output:
The (complex) numerators of the generalzied eigenvalues are: (-0.126,0.569) (-0.126,-0.569) (-0.398,0) (-1.12,0) The (real) denominatore of the generalzied eigenvalues are: -1.56 -1.56 -1.25 0.746 The (complex) generalzied eigenvalues are (alphas./beta): (0.081,-0.365) (0.081,0.365) (0.318,-0) (-1.5,0)
Public types
- using ComplexScalar = std::complex<RealScalar>
- Complex scalar type for MatrixType.
- using ComplexVectorType = Matrix<ComplexScalar, ColsAtCompileTime, 1, Options&~RowMajor, MaxColsAtCompileTime, 1>
- Type for vector of complex scalar values eigenvalues as returned by alphas().
- using EigenvalueType = CwiseBinaryOp<internal::scalar_quotient_op<ComplexScalar, Scalar>, ComplexVectorType, VectorType>
- Expression type for the eigenvalues as returned by eigenvalues().
- using EigenvectorsType = Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime>
- Type for matrix of eigenvectors as returned by eigenvectors().
-
using Index = Eigen::
Index deprecated - using MatrixType = _MatrixType
- Synonym for the template parameter
_MatrixType
. - using Scalar = MatrixType::Scalar
- Scalar type for matrices of type MatrixType.
- using VectorType = Matrix<Scalar, ColsAtCompileTime, 1, Options&~RowMajor, MaxColsAtCompileTime, 1>
- Type for vector of real scalar values eigenvalues as returned by betas().
Constructors, destructors, conversion operators
- GeneralizedEigenSolver()
- Default constructor.
- GeneralizedEigenSolver(Index size) explicit
- Default constructor with memory preallocation.
- GeneralizedEigenSolver(const MatrixType& A, const MatrixType& B, bool computeEigenvectors = true)
- Constructor; computes the generalized eigendecomposition of given matrix pair.
Public functions
- auto alphas() const -> ComplexVectorType
- auto betas() const -> VectorType
- auto compute(const MatrixType& A, const MatrixType& B, bool computeEigenvectors = true) -> GeneralizedEigenSolver&
- Computes generalized eigendecomposition of given matrix.
- auto eigenvalues() const -> EigenvalueType
- Returns an expression of the computed generalized eigenvalues.
- auto setMaxIterations(Index maxIters) -> GeneralizedEigenSolver&
Typedef documentation
template<typename _MatrixType>
typedef std::complex<RealScalar> Eigen:: GeneralizedEigenSolver<_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.
template<typename _MatrixType>
typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options&~RowMajor, MaxColsAtCompileTime, 1> Eigen:: GeneralizedEigenSolver<_MatrixType>:: ComplexVectorType
Type for vector of complex scalar values eigenvalues as returned by alphas().
This is a column vector with entries of type ComplexScalar. The length of the vector is the size of MatrixType.
template<typename _MatrixType>
typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> Eigen:: GeneralizedEigenSolver<_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.
template<typename _MatrixType>
typedef Eigen:: Index Eigen:: GeneralizedEigenSolver<_MatrixType>:: Index
template<typename _MatrixType>
typedef Matrix<Scalar, ColsAtCompileTime, 1, Options&~RowMajor, MaxColsAtCompileTime, 1> Eigen:: GeneralizedEigenSolver<_MatrixType>:: VectorType
Type for vector of real scalar values eigenvalues as returned by betas().
This is a column vector with entries of type Scalar. The length of the vector is the size of MatrixType.
Function documentation
template<typename _MatrixType>
Eigen:: GeneralizedEigenSolver<_MatrixType>:: GeneralizedEigenSolver()
Default constructor.
The default constructor is useful in cases in which the user intends to perform decompositions via EigenSolver::compute(const MatrixType&, bool).
template<typename _MatrixType>
Eigen:: GeneralizedEigenSolver<_MatrixType>:: GeneralizedEigenSolver(Index size) explicit
Default constructor with memory preallocation.
Like the default constructor but with preallocation of the internal data according to the specified problem size.
template<typename _MatrixType>
Eigen:: GeneralizedEigenSolver<_MatrixType>:: GeneralizedEigenSolver(const MatrixType& A,
const MatrixType& B,
bool computeEigenvectors = true)
Constructor; computes the generalized eigendecomposition of given matrix pair.
Parameters | |
---|---|
A in | Square matrix whose eigendecomposition is to be computed. |
B in | Square matrix whose eigendecomposition is to be computed. |
computeEigenvectors in | If true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed. |
This constructor calls compute() to compute the generalized eigenvalues and eigenvectors.
template<typename _MatrixType>
ComplexVectorType Eigen:: GeneralizedEigenSolver<_MatrixType>:: alphas() const
Returns | A const reference to the vectors containing the alpha values |
---|
This vector permits to reconstruct the j-th eigenvalues as alphas(i)/betas(j).
template<typename _MatrixType>
VectorType Eigen:: GeneralizedEigenSolver<_MatrixType>:: betas() const
Returns | A const reference to the vectors containing the beta values |
---|
This vector permits to reconstruct the j-th eigenvalues as alphas(i)/betas(j).
template<typename _MatrixType>
GeneralizedEigenSolver& Eigen:: GeneralizedEigenSolver<_MatrixType>:: compute(const MatrixType& A,
const MatrixType& B,
bool computeEigenvectors = true)
Computes generalized eigendecomposition of given matrix.
Parameters | |
---|---|
A in | Square matrix whose eigendecomposition is to be computed. |
B in | Square matrix whose eigendecomposition is to be computed. |
computeEigenvectors in | If 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 generalized Schur form using the RealQZ class. The generalized Schur decomposition is then used to compute the eigenvalues and eigenvectors.
The cost of the computation is dominated by the cost of the generalized Schur decomposition.
This method reuses of the allocated data in the GeneralizedEigenSolver object.
template<typename _MatrixType>
EigenvalueType Eigen:: GeneralizedEigenSolver<_MatrixType>:: eigenvalues() const
Returns an expression of the computed generalized eigenvalues.
Returns | An expression of the column vector containing the eigenvalues. |
---|
It is a shortcut for this->alphas().cwiseQuotient(this->betas());
Not that betas might contain zeros. It is therefore not recommended to use this function, but rather directly deal with the alphas and betas vectors.
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.
template<typename _MatrixType>
GeneralizedEigenSolver& Eigen:: GeneralizedEigenSolver<_MatrixType>:: setMaxIterations(Index maxIters)
Sets the maximal number of iterations allowed.