template<typename _MatrixType>
Eigen::ComplexEigenSolver class

Computes eigenvalues and eigenvectors of general complex matrices.

Template parameters
_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.

This is defined in the Eigenvalues module. #include <Eigen/Eigenvalues>

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 main function in this class is compute(), which computes the eigenvalues and eigenvectors of a given function. The documentation for that function contains an example showing the main features of the class.

Public types

using ComplexScalar = std::complex<RealScalar>
Complex scalar type for MatrixType.
using EigenvalueType = Matrix<ComplexScalar, ColsAtCompileTime, 1, Options&(~RowMajor), MaxColsAtCompileTime, 1>
Type for vector of eigenvalues as returned by eigenvalues().
using EigenvectorType = 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.

Constructors, destructors, conversion operators

ComplexEigenSolver()
Default constructor.
ComplexEigenSolver(Index size) explicit
Default Constructor with memory preallocation.
template<typename InputType>
ComplexEigenSolver(const EigenBase<InputType>& matrix, bool computeEigenvectors = true) explicit
Constructor; computes eigendecomposition of given matrix.

Public functions

template<typename InputType>
auto compute(const EigenBase<InputType>& matrix, bool computeEigenvectors = true) -> ComplexEigenSolver&
Computes eigendecomposition of given matrix.
auto eigenvalues() const -> const EigenvalueType&
Returns the eigenvalues of given matrix.
auto eigenvectors() const -> const EigenvectorType&
Returns the eigenvectors of given matrix.
auto getMaxIterations() -> Index
Returns the maximum number of iterations.
auto info() const -> ComputationInfo
Reports whether previous computation was successful.
auto setMaxIterations(Index maxIters) -> ComplexEigenSolver&
Sets the maximum number of iterations allowed.

Typedef documentation

template<typename _MatrixType>
typedef std::complex<RealScalar> Eigen::ComplexEigenSolver<_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::ComplexEigenSolver<_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.

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

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::ComplexEigenSolver<_MatrixType>::Index

Function documentation

template<typename _MatrixType>
Eigen::ComplexEigenSolver<_MatrixType>::ComplexEigenSolver()

Default constructor.

The default constructor is useful in cases in which the user intends to perform decompositions via compute().

template<typename _MatrixType>
Eigen::ComplexEigenSolver<_MatrixType>::ComplexEigenSolver(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> template<typename InputType>
Eigen::ComplexEigenSolver<_MatrixType>::ComplexEigenSolver(const EigenBase<InputType>& matrix, bool computeEigenvectors = true) explicit

Constructor; computes eigendecomposition of given matrix.

Parameters
matrix 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 eigendecomposition.

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

Computes eigendecomposition of given matrix.

Parameters
matrix 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 complex 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 Schur form using the ComplexSchur 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 $ O(n^3) $ where $ n $ is the size of the matrix.

Example:

MatrixXcf A = MatrixXcf::Random(4,4);
cout << "Here is a random 4x4 matrix, A:" << endl << A << endl << endl;

ComplexEigenSolver<MatrixXcf> ces;
ces.compute(A);
cout << "The eigenvalues of A are:" << endl << ces.eigenvalues() << endl;
cout << "The matrix of eigenvectors, V, is:" << endl << ces.eigenvectors() << endl << endl;

complex<float> lambda = ces.eigenvalues()[0];
cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
VectorXcf v = ces.eigenvectors().col(0);
cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
cout << "... and A * v = " << endl << A * v << endl << endl;

cout << "Finally, V * D * V^(-1) = " << endl
     << ces.eigenvectors() * ces.eigenvalues().asDiagonal() * ces.eigenvectors().inverse() << endl;

Output:

Here is a random 4x4 matrix, A:
  (-0.211,0.68)  (0.108,-0.444)   (0.435,0.271) (-0.198,-0.687)
  (0.597,0.566) (0.258,-0.0452)  (0.214,-0.717)  (-0.782,-0.74)
 (-0.605,0.823)  (0.0268,-0.27) (-0.514,-0.967)  (-0.563,0.998)
  (0.536,-0.33)   (0.832,0.904)  (0.608,-0.726)  (0.678,0.0259)

The eigenvalues of A are:
 (0.137,0.505)
 (-0.758,1.22)
 (1.52,-0.402)
(-0.691,-1.63)
The matrix of eigenvectors, V, is:
  (-0.246,-0.106)     (0.418,0.263)   (0.0417,-0.296)    (-0.122,0.271)
  (-0.205,-0.629)    (0.466,-0.457)    (0.244,-0.456)      (0.247,0.23)
 (-0.432,-0.0359) (-0.0651,-0.0146)    (-0.191,0.334)   (0.859,-0.0877)
    (-0.301,0.46)    (-0.41,-0.397)     (0.623,0.328)    (-0.116,0.195)

Consider the first eigenvalue, lambda = (0.137,0.505)
If v is the corresponding eigenvector, then lambda * v = 
 (0.0197,-0.139)
    (0.29,-0.19)
(-0.0412,-0.223)
(-0.274,-0.0891)
... and A * v = 
 (0.0197,-0.139)
    (0.29,-0.19)
(-0.0412,-0.223)
(-0.274,-0.0891)

Finally, V * D * V^(-1) = 
  (-0.211,0.68)  (0.108,-0.444)   (0.435,0.271) (-0.198,-0.687)
  (0.597,0.566) (0.258,-0.0452)  (0.214,-0.717)  (-0.782,-0.74)
 (-0.605,0.823)  (0.0268,-0.27) (-0.514,-0.967)  (-0.563,0.998)
  (0.536,-0.33)   (0.832,0.904)  (0.608,-0.726)  (0.678,0.0259)

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

Returns the eigenvalues of given matrix.

Returns A const reference to the column vector containing the eigenvalues.

This function returns a column vector containing the eigenvalues. 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:

MatrixXcf ones = MatrixXcf::Ones(3,3);
ComplexEigenSolver<MatrixXcf> ces(ones, /* computeEigenvectors = */ false);
cout << "The eigenvalues of the 3x3 matrix of ones are:" 
     << endl << ces.eigenvalues() << endl;

Output:

The eigenvalues of the 3x3 matrix of ones are:
(0,-0)
 (0,0)
 (3,0)

template<typename _MatrixType>
const EigenvectorType& Eigen::ComplexEigenSolver<_MatrixType>::eigenvectors() const

Returns the eigenvectors of given matrix.

Returns A const reference to the matrix whose columns are the eigenvectors.

This function returns a matrix whose columns are the eigenvectors. Column $ k $ 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:

MatrixXcf ones = MatrixXcf::Ones(3,3);
ComplexEigenSolver<MatrixXcf> ces(ones);
cout << "The first eigenvector of the 3x3 matrix of ones is:" 
     << endl << ces.eigenvectors().col(1) << endl;

Output:

The first eigenvector of the 3x3 matrix of ones is:
 (0.154,0)
(-0.772,0)
 (0.617,0)

template<typename _MatrixType>
ComputationInfo Eigen::ComplexEigenSolver<_MatrixType>::info() const

Reports whether previous computation was successful.

Returns Success if computation was successful, NoConvergence otherwise.