12#ifndef EIGEN_COMPLEX_EIGEN_SOLVER_H
13#define EIGEN_COMPLEX_EIGEN_SOLVER_H
61 typedef typename MatrixType::Scalar
Scalar;
125 template<
typename InputType>
127 :
m_eivec(matrix.rows(),matrix.cols()),
132 m_matX(matrix.rows(),matrix.cols())
212 template<
typename InputType>
253 void doComputeEigenvectors(
RealScalar matrixnorm);
254 void sortEigenvalues(
bool computeEigenvectors);
258template<
typename MatrixType>
259template<
typename InputType>
263 check_template_parameters();
270 m_schur.compute(matrix.
derived(), computeEigenvectors);
274 m_eivalues = m_schur.matrixT().diagonal();
275 if(computeEigenvectors)
276 doComputeEigenvectors(m_schur.matrixT().norm());
277 sortEigenvalues(computeEigenvectors);
280 m_isInitialized =
true;
281 m_eigenvectorsOk = computeEigenvectors;
286template<
typename MatrixType>
289 const Index n = m_eivalues.size();
295 m_matX = EigenvectorType::Zero(n, n);
296 for(
Index k=n-1 ; k>=0 ; k--)
298 m_matX.coeffRef(k,k) = ComplexScalar(1.0,0.0);
300 for(
Index i=k-1 ; i>=0 ; i--)
302 m_matX.coeffRef(i,k) = -m_schur.matrixT().coeff(i,k);
304 m_matX.coeffRef(i,k) -= (m_schur.matrixT().row(i).segment(i+1,k-i-1) * m_matX.col(k).segment(i+1,k-i-1)).
value();
305 ComplexScalar z = m_schur.matrixT().coeff(i,i) - m_schur.matrixT().coeff(k,k);
306 if(z==ComplexScalar(0))
312 m_matX.coeffRef(i,k) = m_matX.coeff(i,k) / z;
317 m_eivec.noalias() = m_schur.matrixU() * m_matX;
319 for(
Index k=0 ; k<n ; k++)
321 m_eivec.col(k).normalize();
326template<
typename MatrixType>
327void ComplexEigenSolver<MatrixType>::sortEigenvalues(
bool computeEigenvectors)
329 const Index n = m_eivalues.size();
330 for (
Index i=0; i<n; i++)
333 m_eivalues.cwiseAbs().tail(n-i).minCoeff(&k);
338 if(computeEigenvectors)
339 m_eivec.col(i).swap(m_eivec.col(k));
#define eigen_assert(x)
Definition: Macros.h:1047
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Definition: StaticAssert.h:187
\eigenvalues_module
Definition: ComplexEigenSolver.h:46
const EigenvalueType & eigenvalues() const
Returns the eigenvalues of given matrix.
Definition: ComplexEigenSolver.h:182
ComplexEigenSolver & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
Definition: ComplexEigenSolver.h:226
@ MaxColsAtCompileTime
Definition: ComplexEigenSolver.h:57
@ Options
Definition: ComplexEigenSolver.h:55
@ RowsAtCompileTime
Definition: ComplexEigenSolver.h:53
@ ColsAtCompileTime
Definition: ComplexEigenSolver.h:54
@ MaxRowsAtCompileTime
Definition: ComplexEigenSolver.h:56
EigenvectorType m_eivec
Definition: ComplexEigenSolver.h:245
EigenvalueType m_eivalues
Definition: ComplexEigenSolver.h:246
ComplexEigenSolver()
Default constructor.
Definition: ComplexEigenSolver.h:92
std::complex< RealScalar > ComplexScalar
Complex scalar type for MatrixType.
Definition: ComplexEigenSolver.h:71
const EigenvectorType & eigenvectors() const
Returns the eigenvectors of given matrix.
Definition: ComplexEigenSolver.h:157
bool m_isInitialized
Definition: ComplexEigenSolver.h:248
EigenvectorType m_matX
Definition: ComplexEigenSolver.h:250
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition: ComplexEigenSolver.h:61
Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > EigenvectorType
Type for matrix of eigenvectors as returned by eigenvectors().
Definition: ComplexEigenSolver.h:85
ComplexEigenSolver(const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
Constructor; computes eigendecomposition of given matrix.
Definition: ComplexEigenSolver.h:126
NumTraits< Scalar >::Real RealScalar
Definition: ComplexEigenSolver.h:62
ComplexEigenSolver(Index size)
Default Constructor with memory preallocation.
Definition: ComplexEigenSolver.h:107
bool m_eigenvectorsOk
Definition: ComplexEigenSolver.h:249
Eigen::Index Index
Definition: ComplexEigenSolver.h:63
ComplexSchur< MatrixType > m_schur
Definition: ComplexEigenSolver.h:247
static void check_template_parameters()
Definition: ComplexEigenSolver.h:240
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: ComplexEigenSolver.h:219
_MatrixType MatrixType
Synonym for the template parameter _MatrixType.
Definition: ComplexEigenSolver.h:50
Index getMaxIterations()
Returns the maximum number of iterations.
Definition: ComplexEigenSolver.h:233
ComplexEigenSolver & compute(const EigenBase< InputType > &matrix, bool computeEigenvectors=true)
Computes eigendecomposition of given matrix.
Index getMaxIterations()
Returns the maximum number of iterations.
Definition: ComplexSchur.h:235
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: ComplexSchur.h:217
ComplexSchur & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
Definition: ComplexSchur.h:228
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:180
ComputationInfo
Enum for reporting the status of a computation.
Definition: Constants.h:440
@ Success
Computation was successful.
Definition: Constants.h:442
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: MathFunctions.h:1091
EIGEN_DEVICE_FUNC internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar)>::type real_ref(const Scalar &x)
Definition: MathFunctions.h:1237
Namespace containing all symbols from the Eigen library.
Definition: MatrixExponential.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
void swap(wpi::SmallVectorImpl< T > &LHS, wpi::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1299
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:30
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: EigenBase.h:63
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:60
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233