Eigen::PolynomialSolver< Scalar_, Deg_ > Class Template Reference

A polynomial solver. More...

#include <PolynomialSolver.h>

+ Inheritance diagram for Eigen::PolynomialSolver< Scalar_, Deg_ >:

Public Types

typedef PolynomialSolverBase< Scalar_, Deg_ > PS_Base
 
typedef Matrix< Scalar, Deg_, Deg_ > CompanionMatrixType
 
typedef std::conditional_t< NumTraits< Scalar >::IsComplex, ComplexEigenSolver< CompanionMatrixType >, EigenSolver< CompanionMatrixType > > EigenSolverType
 
typedef std::conditional_t< NumTraits< Scalar >::IsComplex, Scalar, std::complex< Scalar > > ComplexScalar
 
- Public Types inherited from Eigen::PolynomialSolverBase< Scalar_, Deg_ >
typedef Scalar_ Scalar
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef std::complex< RealScalarRootType
 
typedef Matrix< RootType, Deg_, 1 > RootsType
 
typedef DenseIndex Index
 

Public Member Functions

template<typename OtherPolynomial >
void compute (const OtherPolynomial &poly)
 
template<typename OtherPolynomial >
 PolynomialSolver (const OtherPolynomial &poly)
 
 PolynomialSolver ()
 
- Public Member Functions inherited from Eigen::PolynomialSolverBase< Scalar_, Deg_ >
template<typename OtherPolynomial >
 PolynomialSolverBase (const OtherPolynomial &poly)
 
 PolynomialSolverBase ()
 
const RootsTyperoots () const
 
template<typename Stl_back_insertion_sequence >
void realRoots (Stl_back_insertion_sequence &bi_seq, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RootTypegreatestRoot () const
 
const RootTypesmallestRoot () const
 
const RealScalarabsGreatestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RealScalarabsSmallestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RealScalargreatestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RealScalarsmallestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 

Protected Attributes

EigenSolverType m_eigenSolver
 
RootsType m_roots
 
- Protected Attributes inherited from Eigen::PolynomialSolverBase< Scalar_, Deg_ >
RootsType m_roots
 

Additional Inherited Members

- Protected Member Functions inherited from Eigen::PolynomialSolverBase< Scalar_, Deg_ >
template<typename OtherPolynomial >
void setPolynomial (const OtherPolynomial &poly)
 
template<typename squaredNormBinaryPredicate >
const RootTypeselectComplexRoot_withRespectToNorm (squaredNormBinaryPredicate &pred) const
 
template<typename squaredRealPartBinaryPredicate >
const RealScalarselectRealRoot_withRespectToAbsRealPart (squaredRealPartBinaryPredicate &pred, bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
template<typename RealPartBinaryPredicate >
const RealScalarselectRealRoot_withRespectToRealPart (RealPartBinaryPredicate &pred, bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 

Detailed Description

template<typename Scalar_, int Deg_>
class Eigen::PolynomialSolver< Scalar_, Deg_ >

A polynomial solver.

Computes the complex roots of a real polynomial.

Parameters
Scalar_the scalar type, i.e., the type of the polynomial coefficients
Deg_the degree of the polynomial, can be a compile time value or Dynamic. Notice that the number of polynomial coefficients is Deg_+1.

This class implements a polynomial solver and provides convenient methods such as

  • real roots,
  • greatest, smallest complex roots,
  • real roots with greatest, smallest absolute real value.
  • greatest, smallest real roots.

WARNING: this polynomial solver is experimental, part of the unsupported Eigen modules.

Currently a QR algorithm is used to compute the eigenvalues of the companion matrix of the polynomial to compute its roots. This supposes that the complex moduli of the roots are all distinct: e.g. there should be no multiple roots or conjugate roots for instance. With 32bit (float) floating types this problem shows up frequently. However, almost always, correct accuracy is reached even in these cases for 64bit (double) floating types and small polynomial degree (<20).

Member Typedef Documentation

◆ CompanionMatrixType

template<typename Scalar_ , int Deg_>
typedef Matrix<Scalar, Deg_, Deg_> Eigen::PolynomialSolver< Scalar_, Deg_ >::CompanionMatrixType

◆ ComplexScalar

template<typename Scalar_ , int Deg_>
typedef std::conditional_t<NumTraits<Scalar>::IsComplex, Scalar, std::complex<Scalar> > Eigen::PolynomialSolver< Scalar_, Deg_ >::ComplexScalar

◆ EigenSolverType

template<typename Scalar_ , int Deg_>
typedef std::conditional_t<NumTraits<Scalar>::IsComplex, ComplexEigenSolver<CompanionMatrixType>, EigenSolver<CompanionMatrixType> > Eigen::PolynomialSolver< Scalar_, Deg_ >::EigenSolverType

◆ PS_Base

template<typename Scalar_ , int Deg_>
typedef PolynomialSolverBase<Scalar_, Deg_> Eigen::PolynomialSolver< Scalar_, Deg_ >::PS_Base

Constructor & Destructor Documentation

◆ PolynomialSolver() [1/2]

template<typename Scalar_ , int Deg_>
template<typename OtherPolynomial >
Eigen::PolynomialSolver< Scalar_, Deg_ >::PolynomialSolver ( const OtherPolynomial &  poly)
inline
347  {
348  compute(poly);
349  }
void compute(const OtherPolynomial &poly)
Definition: PolynomialSolver.h:316

References Eigen::PolynomialSolver< Scalar_, Deg_ >::compute().

◆ PolynomialSolver() [2/2]

template<typename Scalar_ , int Deg_>
Eigen::PolynomialSolver< Scalar_, Deg_ >::PolynomialSolver ( )
inline
351 {}

Member Function Documentation

◆ compute()

template<typename Scalar_ , int Deg_>
template<typename OtherPolynomial >
void Eigen::PolynomialSolver< Scalar_, Deg_ >::compute ( const OtherPolynomial &  poly)
inline

Computes the complex roots of a new polynomial.

316  {
317  eigen_assert(Scalar(0) != poly[poly.size() - 1]);
318  eigen_assert(poly.size() > 1);
319  if (poly.size() > 2) {
320  internal::companion<Scalar, Deg_> companion(poly);
321  companion.balance();
322  m_eigenSolver.compute(companion.denseMatrix());
324  m_roots = m_eigenSolver.eigenvalues();
325  // cleanup noise in imaginary part of real roots:
326  // if the imaginary part is rather small compared to the real part
327  // and that cancelling the imaginary part yield a smaller evaluation,
328  // then it's safe to keep the real part only.
329  RealScalar coarse_prec = RealScalar(std::pow(4, poly.size() + 1)) * NumTraits<RealScalar>::epsilon();
330  for (Index i = 0; i < m_roots.size(); ++i) {
332  coarse_prec)) {
334  if (numext::abs(poly_eval(poly, as_real_root)) <= numext::abs(poly_eval(poly, m_roots[i]))) {
335  m_roots[i] = as_real_root;
336  }
337  }
338  }
339  } else if (poly.size() == 2) {
340  m_roots.resize(1);
341  m_roots[0] = -poly[0] / poly[1];
342  }
343  }
AnnoyingScalar imag(const AnnoyingScalar &)
Definition: AnnoyingScalar.h:132
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition: Macros.h:910
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:294
NumTraits< Scalar >::Real RealScalar
Definition: PolynomialSolver.h:37
Scalar_ Scalar
Definition: PolynomialSolver.h:36
DenseIndex Index
Definition: PolynomialSolver.h:41
EigenSolverType m_eigenSolver
Definition: PolynomialSolver.h:355
RootsType m_roots
Definition: PolynomialSolver.h:261
std::conditional_t< NumTraits< Scalar >::IsComplex, Scalar, std::complex< Scalar > > ComplexScalar
Definition: PolynomialSolver.h:311
float real
Definition: datatypes.h:10
@ Success
Definition: Constants.h:440
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625
EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: MathFunctions.h:1916
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)
Definition: MathFunctions.h:1355
T poly_eval(const Polynomials &poly, const T &x)
Definition: PolynomialUtils.h:47
double epsilon
Definition: osc_ring_sarah_asymptotics.h:43

References Eigen::numext::abs(), Eigen::internal::companion< Scalar_, Deg_ >::balance(), Eigen::internal::companion< Scalar_, Deg_ >::denseMatrix(), eigen_assert, oomph::SarahBL::epsilon, i, imag(), Eigen::internal::isMuchSmallerThan(), Eigen::PolynomialSolver< Scalar_, Deg_ >::m_eigenSolver, Eigen::PolynomialSolver< Scalar_, Deg_ >::m_roots, Eigen::poly_eval(), Eigen::bfloat16_impl::pow(), Eigen::PlainObjectBase< Derived >::resize(), and Eigen::Success.

Referenced by Eigen::PolynomialSolver< Scalar_, Deg_ >::PolynomialSolver(), and Eigen::PolynomialSolver< Scalar_, 1 >::PolynomialSolver().

Member Data Documentation

◆ m_eigenSolver

template<typename Scalar_ , int Deg_>
EigenSolverType Eigen::PolynomialSolver< Scalar_, Deg_ >::m_eigenSolver
protected

◆ m_roots

template<typename Scalar_ , int Deg_>
RootsType Eigen::PolynomialSolverBase< Scalar_, Deg_ >::m_roots
protected

The documentation for this class was generated from the following file: