27 #ifndef EIGEN_COMPLEX_EIGEN_SOLVER_H
28 #define EIGEN_COMPLEX_EIGEN_SOLVER_H
76 typedef typename MatrixType::Scalar
Scalar;
78 typedef typename MatrixType::Index
Index;
141 :
m_eivec(matrix.rows(),matrix.cols()),
146 m_matX(matrix.rows(),matrix.cols())
148 compute(matrix, computeEigenvectors);
247 void doComputeEigenvectors(
RealScalar matrixnorm);
248 void sortEigenvalues(
bool computeEigenvectors);
252 template<
typename MatrixType>
256 assert(matrix.cols() == matrix.rows());
260 m_schur.
compute(matrix, computeEigenvectors);
264 m_eivalues = m_schur.matrixT().diagonal();
265 if(computeEigenvectors)
266 doComputeEigenvectors(matrix.norm());
267 sortEigenvalues(computeEigenvectors);
270 m_isInitialized =
true;
271 m_eigenvectorsOk = computeEigenvectors;
276 template<
typename MatrixType>
279 const Index n = m_eivalues.size();
283 m_matX = EigenvectorType::Zero(n, n);
284 for(Index k=n-1 ; k>=0 ; k--)
286 m_matX.coeffRef(k,k) = ComplexScalar(1.0,0.0);
288 for(Index i=k-1 ; i>=0 ; i--)
290 m_matX.coeffRef(i,k) = -m_schur.matrixT().coeff(i,k);
292 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();
293 ComplexScalar z = m_schur.matrixT().coeff(i,i) - m_schur.matrixT().coeff(k,k);
294 if(z==ComplexScalar(0))
300 m_matX.coeffRef(i,k) = m_matX.coeff(i,k) / z;
305 m_eivec.noalias() = m_schur.matrixU() * m_matX;
307 for(Index k=0 ; k<n ; k++)
309 m_eivec.col(k).normalize();
314 template<
typename MatrixType>
315 void ComplexEigenSolver<MatrixType>::sortEigenvalues(
bool computeEigenvectors)
317 const Index n = m_eivalues.size();
318 for (Index i=0; i<n; i++)
321 m_eivalues.cwiseAbs().tail(n-i).minCoeff(&k);
325 std::swap(m_eivalues[k],m_eivalues[i]);
326 if(computeEigenvectors)
327 m_eivec.col(i).swap(m_eivec.col(k));
334 #endif // EIGEN_COMPLEX_EIGEN_SOLVER_H