Eigen  5.0.1
 
Loading...
Searching...
No Matches
Eigen::ComplexEigenSolver< MatrixType_ > Class Template Reference

#include <Eigen/src/Eigenvalues/ComplexEigenSolver.h>

Detailed Description

template<typename MatrixType_>
class Eigen::ComplexEigenSolver< MatrixType_ >

Computes eigenvalues and eigenvectors of general complex matrices.

This is defined in the Eigenvalues module.

#include <Eigen/Eigenvalues>
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.

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 matrix. The documentation for that function contains an example showing the main features of the class.

See also
class EigenSolver, class SelfAdjointEigenSolver

Public Types

using ComplexScalar
 Complex scalar type for MatrixType.
 
using EigenvalueType
 Type for vector of eigenvalues as returned by eigenvalues().
 
using EigenvectorType
 Type for matrix of eigenvectors as returned by eigenvectors().
 
using Index
 
using MatrixType
 Synonym for the template parameter MatrixType_.
 
using Scalar
 Scalar type for matrices of type MatrixType.
 

Public Member Functions

 ComplexEigenSolver ()
 Default constructor.
 
template<typename InputType>
 ComplexEigenSolver (const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
 Constructor; computes eigendecomposition of given matrix.
 
template<typename InputType>
 ComplexEigenSolver (EigenBase< InputType > &matrix, bool computeEigenvectors=true)
 Constructor for inplace decomposition .
 
 ComplexEigenSolver (Index size)
 Default Constructor with memory preallocation.
 
template<typename InputType>
ComplexEigenSolver & compute (const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
 Computes eigendecomposition of given matrix.
 
const EigenvalueType & eigenvalues () const
 Returns the eigenvalues of given matrix.
 
const EigenvectorType & eigenvectors () const
 Returns the eigenvectors of given matrix.
 
Index getMaxIterations () const
 Returns the maximum number of iterations.
 
ComputationInfo info () const
 Reports whether previous computation was successful.
 
ComplexEigenSolver & setMaxIterations (Index maxIters)
 Sets the maximum number of iterations allowed.
 

Member Typedef Documentation

◆ ComplexScalar

template<typename MatrixType_>
using 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.

◆ EigenvalueType

template<typename MatrixType_>
using 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.

◆ EigenvectorType

template<typename MatrixType_>
using 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.

◆ Index

template<typename MatrixType_>
using Eigen::ComplexEigenSolver< MatrixType_ >::Index

Constructor & Destructor Documentation

◆ ComplexEigenSolver() [1/4]

template<typename MatrixType_>
Eigen::ComplexEigenSolver< MatrixType_ >::ComplexEigenSolver ( )
inline

Default constructor.

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

◆ ComplexEigenSolver() [2/4]

template<typename MatrixType_>
Eigen::ComplexEigenSolver< MatrixType_ >::ComplexEigenSolver ( 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
ComplexEigenSolver()

◆ ComplexEigenSolver() [3/4]

template<typename MatrixType_>
template<typename InputType>
Eigen::ComplexEigenSolver< MatrixType_ >::ComplexEigenSolver ( 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 computes the eigendecomposition as compute() does.

◆ ComplexEigenSolver() [4/4]

template<typename MatrixType_>
template<typename InputType>
Eigen::ComplexEigenSolver< MatrixType_ >::ComplexEigenSolver ( EigenBase< InputType > & matrix,
bool computeEigenvectors = true )
inlineexplicit

Constructor for inplace decomposition .

Parameters
[in,out]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.

When MatrixType is a Ref<> (which requires a complex scalar type), the decomposition is computed within the memory of matrix, whose content is destroyed; the results are stored in the decomposition object. Otherwise this constructor behaves like ComplexEigenSolver(const EigenBase<InputType>&, bool).

Member Function Documentation

◆ compute()

template<typename MatrixType_>
template<typename InputType>
ComplexEigenSolver & Eigen::ComplexEigenSolver< 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 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:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
MatrixXcf A = MatrixXcf::Random(4, 4);
cout << "Here is a random 4x4 matrix, A:" << endl << A << endl << endl;
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;
ComplexEigenSolver & compute(const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
Computes eigendecomposition of given matrix.
ComplexEigenSolver()
Default constructor.
Definition ComplexEigenSolver.h:96
const EigenvectorType & eigenvectors() const
Returns the eigenvectors of given matrix.
Definition ComplexEigenSolver.h:167
const EigenvalueType & eigenvalues() const
Returns the eigenvalues of given matrix.
Definition ComplexEigenSolver.h:191
Matrix< std::complex< float >, Dynamic, 1 > VectorXcf
DynamicĂ—1 vector of type std::complex<float>.
Definition Matrix.h:490
Matrix< std::complex< float >, Dynamic, Dynamic > MatrixXcf
DynamicĂ—Dynamic matrix of type std::complex<float>.
Definition Matrix.h:490

Output:

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

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

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

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

◆ eigenvalues()

template<typename MatrixType_>
const EigenvalueType & Eigen::ComplexEigenSolver< 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 ComplexEigenSolver(const MatrixType& matrix, bool) or the member function compute(const MatrixType& matrix, bool) has been called before to compute the eigendecomposition of a matrix.

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:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
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)

◆ eigenvectors()

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

Returns the eigenvectors of given matrix.

Returns
A const reference to the matrix whose columns are the eigenvectors.
Precondition
Either the constructor ComplexEigenSolver(const MatrixType& matrix, bool) or the member function compute(const MatrixType& matrix, bool) has been called before to compute the eigendecomposition of a matrix, and computeEigenvectors was set to true (the default).

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:

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
MatrixXcf ones = MatrixXcf::Ones(3, 3);
cout << "The first eigenvector of the 3x3 matrix of ones is:" << endl << ces.eigenvectors().col(0) << endl;

Output:

The first eigenvector of the 3x3 matrix of ones is:
(-0.816,0)
 (0.408,0)
 (0.408,0)

◆ info()

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

Reports whether previous computation was successful.

Returns
Success if computation was successful, NoConvergence otherwise.

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