12 #ifndef EIGEN_COMPLEX_EIGEN_SOLVER_H
13 #define EIGEN_COMPLEX_EIGEN_SOLVER_H
15 #include "./ComplexSchur.h"
53 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
54 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
55 Options = MatrixType::Options,
56 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
57 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
61 typedef typename MatrixType::Scalar
Scalar;
63 typedef typename MatrixType::Index Index;
96 m_isInitialized(false),
97 m_eigenvectorsOk(false),
108 : m_eivec(size, size),
111 m_isInitialized(false),
112 m_eigenvectorsOk(false),
126 : m_eivec(matrix.rows(),matrix.cols()),
127 m_eivalues(matrix.cols()),
128 m_schur(matrix.rows()),
129 m_isInitialized(false),
130 m_eigenvectorsOk(false),
131 m_matX(matrix.rows(),matrix.cols())
133 compute(matrix, computeEigenvectors);
158 eigen_assert(m_isInitialized &&
"ComplexEigenSolver is not initialized.");
159 eigen_assert(m_eigenvectorsOk &&
"The eigenvectors have not been computed together with the eigenvalues.");
183 eigen_assert(m_isInitialized &&
"ComplexEigenSolver is not initialized.");
219 eigen_assert(m_isInitialized &&
"ComplexEigenSolver is not initialized.");
220 return m_schur.
info();
240 bool m_isInitialized;
241 bool m_eigenvectorsOk;
245 void doComputeEigenvectors(
const RealScalar& matrixnorm);
246 void sortEigenvalues(
bool computeEigenvectors);
250 template<
typename MatrixType>
251 ComplexEigenSolver<MatrixType>&
255 eigen_assert(matrix.cols() == matrix.rows());
259 m_schur.compute(matrix, computeEigenvectors);
263 m_eivalues = m_schur.matrixT().diagonal();
264 if(computeEigenvectors)
265 doComputeEigenvectors(matrix.norm());
266 sortEigenvalues(computeEigenvectors);
269 m_isInitialized =
true;
270 m_eigenvectorsOk = computeEigenvectors;
275 template<
typename MatrixType>
278 const Index n = m_eivalues.size();
282 m_matX = EigenvectorType::Zero(n, n);
283 for(Index k=n-1 ; k>=0 ; k--)
285 m_matX.coeffRef(k,k) = ComplexScalar(1.0,0.0);
287 for(Index i=k-1 ; i>=0 ; i--)
289 m_matX.coeffRef(i,k) = -m_schur.matrixT().coeff(i,k);
291 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();
292 ComplexScalar z = m_schur.matrixT().coeff(i,i) - m_schur.matrixT().coeff(k,k);
293 if(z==ComplexScalar(0))
299 m_matX.coeffRef(i,k) = m_matX.coeff(i,k) / z;
304 m_eivec.noalias() = m_schur.matrixU() * m_matX;
306 for(Index k=0 ; k<n ; k++)
308 m_eivec.col(k).normalize();
313 template<
typename MatrixType>
314 void ComplexEigenSolver<MatrixType>::sortEigenvalues(
bool computeEigenvectors)
316 const Index n = m_eivalues.size();
317 for (Index i=0; i<n; i++)
320 m_eivalues.cwiseAbs().tail(n-i).minCoeff(&k);
324 std::swap(m_eivalues[k],m_eivalues[i]);
325 if(computeEigenvectors)
326 m_eivec.col(i).swap(m_eivec.col(k));
333 #endif // EIGEN_COMPLEX_EIGEN_SOLVER_H