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).
template<typename Scalar_ , int Deg_>
template<typename OtherPolynomial >
Computes the complex roots of a new polynomial.
319 if (poly.size() > 2) {
320 internal::companion<Scalar, Deg_> companion(poly);
339 }
else if (poly.size() == 2) {
341 m_roots[0] = -poly[0] / poly[1];
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().