11 #ifndef EIGEN_EIGENSOLVER_H 12 #define EIGEN_EIGENSOLVER_H 80 typedef typename MatrixType::Scalar
Scalar;
82 typedef typename MatrixType::Index
Index;
146 EigenSolver(
const MatrixType& matrix,
bool computeEigenvectors =
true)
147 :
m_eivec(matrix.rows(), matrix.cols()),
152 m_matT(matrix.rows(), matrix.cols()),
155 compute(matrix, computeEigenvectors);
312 template<
typename MatrixType>
318 for (
Index i=0; i<n; ++i)
332 template<
typename MatrixType>
339 for (
Index j=0; j<n; ++j)
344 matV.col(j) =
m_eivec.col(j).template cast<ComplexScalar>();
345 matV.col(j).normalize();
350 for (
Index i=0; i<n; ++i)
355 matV.col(j).normalize();
356 matV.col(j+1).normalize();
363 template<
typename MatrixType>
377 if (computeEigenvectors)
383 while (i < matrix.cols())
385 if (i == matrix.cols() - 1 ||
m_matT.coeff(i+1, i) ==
Scalar(0))
401 if (computeEigenvectors)
412 template<
typename Scalar>
421 return std::complex<Scalar>((xr + r*xi)/d, (xi - r*xr)/d);
427 return std::complex<Scalar>((r*xr + xi)/d, (r*xi - xr)/d);
432 template<
typename MatrixType>
441 for (
Index j = 0; j < size; ++j)
443 norm +=
m_matT.row(j).segment((std::max)(j-1,
Index(0)), size-(std::max)(j-1,
Index(0))).cwiseAbs().sum();
452 for (
Index n = size-1; n >= 0; n--)
460 Scalar lastr(0), lastw(0);
463 m_matT.coeffRef(n,n) = 1.0;
464 for (
Index i = n-1; i >= 0; i--)
480 m_matT.coeffRef(i,n) = -r / w;
482 m_matT.coeffRef(i,n) = -r / (eps * norm);
489 Scalar t = (x * lastr - lastw * r) / denom;
492 m_matT.coeffRef(i+1,n) = (-r - w * t) / x;
494 m_matT.coeffRef(i+1,n) = (-lastr - y * t) / lastw;
499 if ((eps * t) * t >
Scalar(1))
500 m_matT.col(n).tail(size-i) /= t;
504 else if (q <
Scalar(0) && n > 0)
506 Scalar lastra(0), lastsa(0), lastw(0);
517 std::complex<Scalar> cc = cdiv<Scalar>(0.0,-
m_matT.coeff(n-1,n),
m_matT.coeff(n-1,n-1)-p,q);
521 m_matT.coeffRef(n,n-1) = 0.0;
522 m_matT.coeffRef(n,n) = 1.0;
523 for (
Index i = n-2; i >= 0; i--)
540 std::complex<Scalar> cc =
cdiv(-ra,-sa,w,q);
551 if ((vr == 0.0) && (vi == 0.0))
554 std::complex<Scalar> cc =
cdiv(x*lastra-lastw*ra+q*sa,x*lastsa-lastw*sa-q*ra,vr,vi);
559 m_matT.coeffRef(i+1,n-1) = (-ra - w *
m_matT.coeff(i,n-1) + q *
m_matT.coeff(i,n)) / x;
564 cc =
cdiv(-lastra-y*
m_matT.coeff(i,n-1),-lastsa-y*
m_matT.coeff(i,n),lastw,q);
573 if ((eps * t) * t >
Scalar(1))
574 m_matT.block(i, n-1, size-i, 2) /= t;
589 for (
Index j = size-1; j >= 0; j--)
598 #endif // EIGEN_EIGENSOLVER_H
MatrixType pseudoEigenvalueMatrix() const
Returns the block-diagonal matrix in the pseudo-eigendecomposition.
const MatrixType & pseudoEigenvectors() const
Returns the pseudo-eigenvectors of given matrix.
Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > EigenvectorsType
Type for matrix of eigenvectors as returned by eigenvectors().
IntermediateState sqrt(const Expression &arg)
EigenSolver(Index size)
Default constructor with memory preallocation.
std::complex< Scalar > cdiv(const Scalar &xr, const Scalar &xi, const Scalar &yr, const Scalar &yi)
RealReturnType real() const
iterative scaling algorithm to equilibrate rows and column norms in matrices
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Index getMaxIterations()
Returns the maximum number of iterations.
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
RealSchur< MatrixType > m_realSchur
EigenSolver(const MatrixType &matrix, bool computeEigenvectors=true)
Constructor; computes eigendecomposition of given matrix.
Index getMaxIterations()
Returns the maximum number of iterations.
Matrix< Scalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > ColumnVectorType
NumTraits< Scalar >::Real RealScalar
ComputationInfo info() const
EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
Provides a generic way to set and pass user-specified options.
EigenSolver & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
std::complex< RealScalar > ComplexScalar
Complex scalar type for MatrixType.
EIGEN_STRONG_INLINE Index rows() const
const MatrixType & matrixT() const
Returns the quasi-triangular matrix in the Schur decomposition.
RealSchur & compute(const MatrixType &matrix, bool computeU=true)
Computes Schur decomposition of given matrix.
_MatrixType MatrixType
Synonym for the template parameter _MatrixType.
EigenvectorsType eigenvectors() const
Returns the eigenvectors of given matrix.
EigenSolver()
Default constructor.
const MatrixType & matrixU() const
Returns the orthogonal matrix in the Schur decomposition.
RealSchur & setMaxIterations(Index maxIters)
Sets the maximum number of iterations allowed.
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > abs() const
EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
void doComputeEigenvectors()
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
const EigenvalueType & eigenvalues() const
Returns the eigenvalues of given matrix.
Computes eigenvalues and eigenvectors of general matrices.
ComputationInfo info() const
Reports whether previous computation was successful.
EigenvalueType m_eivalues
const ImagReturnType imag() const
Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > EigenvalueType
Type for vector of eigenvalues as returned by eigenvalues().
EigenSolver & compute(const MatrixType &matrix, bool computeEigenvectors=true)
Computes eigendecomposition of given matrix.