12 #ifndef EIGEN_GENERALIZEDEIGENSOLVER_H
13 #define EIGEN_GENERALIZEDEIGENSOLVER_H
285 template<
typename MatrixType>
289 check_template_parameters();
295 m_valuesOkay =
false;
296 m_vectorsOkay =
false;
299 m_realQZ.compute(
A,
B, computeEigenvectors);
300 if (m_realQZ.info() ==
Success)
303 m_alphas.resize(
size);
304 m_betas.resize(
size);
305 if (computeEigenvectors)
320 if (i ==
size - 1 || mS.coeff(i+1, i) ==
Scalar(0))
323 m_alphas.
coeffRef(i) = mS.diagonal().coeff(i);
324 m_betas.coeffRef(i) = mT.diagonal().coeff(i);
325 if (computeEigenvectors)
327 v.setConstant(
Scalar(0.0));
328 v.coeffRef(i) =
Scalar(1.0);
334 const Scalar beta = m_betas.coeffRef(i);
335 for (
Index j = i-1; j >= 0; j--)
337 const Index st = j+1;
338 const Index sz = i-j;
339 if (j > 0 && mS.coeff(j, j-1) !=
Scalar(0))
342 Matrix<Scalar, 2, 1> rhs = (
alpha*mT.template block<2,Dynamic>(j-1,st,2,sz) - beta*mS.template block<2,Dynamic>(j-1,st,2,sz)) .lazyProduct( v.segment(st,sz) );
344 v.template segment<2>(j-1) = lhs.partialPivLu().solve(rhs);
349 v.coeffRef(j) = -v.segment(st,sz).transpose().cwiseProduct(beta*mS.block(j,st,1,sz) -
alpha*mT.block(j,st,1,sz)).sum() / (beta*mS.coeffRef(j,j) -
alpha*mT.coeffRef(j,j));
353 m_eivec.col(i).real().noalias() = m_realQZ.matrixZ().transpose() * v;
354 m_eivec.col(i).real().normalize();
355 m_eivec.col(i).imag().setConstant(0);
367 b = mT.diagonal().coeff(i+1);
368 const RealScalar beta = m_betas.coeffRef(i) = m_betas.coeffRef(i+1) =
a*
b;
377 m_alphas.coeffRef(i+1) =
alpha;
379 if (computeEigenvectors) {
384 cv.
coeffRef(i) = -(
static_cast<Scalar>(beta*mS.coeffRef(i,i+1)) -
alpha*mT.coeffRef(i,i+1))
385 / (
static_cast<Scalar>(beta*mS.coeffRef(i,i)) -
alpha*mT.coeffRef(i,i));
386 for (
Index j = i-1; j >= 0; j--)
388 const Index st = j+1;
389 const Index sz = i+1-j;
390 if (j > 0 && mS.coeff(j, j-1) !=
Scalar(0))
393 Matrix<ComplexScalar, 2, 1> rhs = (
alpha*mT.template block<2,Dynamic>(j-1,st,2,sz) - beta*mS.template block<2,Dynamic>(j-1,st,2,sz)) .lazyProduct( cv.segment(st,sz) );
395 cv.template segment<2>(j-1) = lhs.partialPivLu().solve(rhs);
398 cv.
coeffRef(j) = cv.segment(st,sz).transpose().cwiseProduct(beta*mS.block(j,st,1,sz) -
alpha*mT.block(j,st,1,sz)).sum()
399 / (
alpha*mT.coeffRef(j,j) -
static_cast<Scalar>(beta*mS.coeffRef(j,j)));
402 m_eivec.col(i+1).noalias() = (m_realQZ.matrixZ().transpose() * cv);
403 m_eivec.col(i+1).normalize();
404 m_eivec.col(i) = m_eivec.col(i+1).conjugate();
411 m_vectorsOkay = computeEigenvectors;
418 #endif // EIGEN_GENERALIZEDEIGENSOLVER_H