Polynomials module

This module provides a QR based polynomial solver. More...

Classes

class  Eigen::PolynomialSolver< Scalar_, Deg_ >
 A polynomial solver. More...
 
class  Eigen::PolynomialSolverBase< Scalar_, Deg_ >
 Defined to be inherited by polynomial solvers: it provides convenient methods such as. More...
 

Functions

template<typename Polynomial >
NumTraits< typename Polynomial::Scalar >::Real Eigen::cauchy_max_bound (const Polynomial &poly)
 
template<typename Polynomial >
NumTraits< typename Polynomial::Scalar >::Real Eigen::cauchy_min_bound (const Polynomial &poly)
 
template<typename Polynomials , typename T >
T Eigen::poly_eval (const Polynomials &poly, const T &x)
 
template<typename Polynomials , typename T >
T Eigen::poly_eval_horner (const Polynomials &poly, const T &x)
 
template<typename RootVector , typename Polynomial >
void Eigen::roots_to_monicPolynomial (const RootVector &rv, Polynomial &poly)
 

Detailed Description

This module provides a QR based polynomial solver.

To use this module, add

at the start of your source file.

Function Documentation

◆ cauchy_max_bound()

template<typename Polynomial >
NumTraits<typename Polynomial::Scalar>::Real Eigen::cauchy_max_bound ( const Polynomial &  poly)
inline
Returns
a maximum bound for the absolute value of any root of the polynomial.
Parameters
[in]poly: the vector of coefficients of the polynomial ordered by degrees i.e. poly[i] is the coefficient of degree i of the polynomial e.g. \( 1 + 3x^2 \) is stored as a vector \( [ 1, 0, 3 ] \).
Precondition
the leading coefficient of the input polynomial poly must be non zero

Definition at line 77 of file PolynomialUtils.h.

78 {
79  using std::abs;
80  typedef typename Polynomial::Scalar Scalar;
81  typedef typename NumTraits<Scalar>::Real Real;
82 
83  eigen_assert( Scalar(0) != poly[poly.size()-1] );
84  const Scalar inv_leading_coeff = Scalar(1)/poly[poly.size()-1];
85  Real cb(0);
86 
87  for( DenseIndex i=0; i<poly.size()-1; ++i ){
88  cb += abs(poly[i]*inv_leading_coeff); }
89  return cb + Real(1);
90 }
int i
#define eigen_assert(x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
adouble abs(const adouble &x)
Definition: AdolcForward:74

◆ cauchy_min_bound()

template<typename Polynomial >
NumTraits<typename Polynomial::Scalar>::Real Eigen::cauchy_min_bound ( const Polynomial &  poly)
inline
Returns
a minimum bound for the absolute value of any non zero root of the polynomial.
Parameters
[in]poly: the vector of coefficients of the polynomial ordered by degrees i.e. poly[i] is the coefficient of degree i of the polynomial e.g. \( 1 + 3x^2 \) is stored as a vector \( [ 1, 0, 3 ] \).

Definition at line 100 of file PolynomialUtils.h.

101 {
102  using std::abs;
103  typedef typename Polynomial::Scalar Scalar;
104  typedef typename NumTraits<Scalar>::Real Real;
105 
106  DenseIndex i=0;
107  while( i<poly.size()-1 && Scalar(0) == poly(i) ){ ++i; }
108  if( poly.size()-1 == i ){
109  return Real(1); }
110 
111  const Scalar inv_min_coeff = Scalar(1)/poly[i];
112  Real cb(1);
113  for( DenseIndex j=i+1; j<poly.size(); ++j ){
114  cb += abs(poly[j]*inv_min_coeff); }
115  return Real(1)/cb;
116 }
std::ptrdiff_t j

◆ poly_eval()

template<typename Polynomials , typename T >
T Eigen::poly_eval ( const Polynomials &  poly,
const T x 
)
inline
Returns
the evaluation of the polynomial at x using stabilized Horner algorithm.
Parameters
[in]poly: the vector of coefficients of the polynomial ordered by degrees i.e. poly[i] is the coefficient of degree i of the polynomial e.g. \( 1 + 3x^2 \) is stored as a vector \( [ 1, 0, 3 ] \).
[in]x: the value to evaluate the polynomial at.

Definition at line 48 of file PolynomialUtils.h.

49 {
50  typedef typename NumTraits<T>::Real Real;
51 
52  if( numext::abs2( x ) <= Real(1) ){
53  return poly_eval_horner( poly, x ); }
54  else
55  {
56  T val=poly[0];
57  T inv_x = T(1)/x;
58  for( DenseIndex i=1; i<poly.size(); ++i ){
59  val = val*inv_x + poly[i]; }
60 
61  return numext::pow(x,(T)(poly.size()-1)) * val;
62  }
63 }
T poly_eval_horner(const Polynomials &poly, const T &x)
Eigen::AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(internal::remove_all_t< DerType >, typename internal::traits< internal::remove_all_t< DerType >>::Scalar, product) > pow(const Eigen::AutoDiffScalar< DerType > &x, const typename internal::traits< internal::remove_all_t< DerType >>::Scalar &y)
adouble abs2(const adouble &x)
Definition: AdolcForward:75

◆ poly_eval_horner()

template<typename Polynomials , typename T >
T Eigen::poly_eval_horner ( const Polynomials &  poly,
const T x 
)
inline
Returns
the evaluation of the polynomial at x using Horner algorithm.
Parameters
[in]poly: the vector of coefficients of the polynomial ordered by degrees i.e. poly[i] is the coefficient of degree i of the polynomial e.g. \( 1 + 3x^2 \) is stored as a vector \( [ 1, 0, 3 ] \).
[in]x: the value to evaluate the polynomial at.
Note
for stability: \( |x| \le 1 \)

Definition at line 30 of file PolynomialUtils.h.

31 {
32  T val=poly[poly.size()-1];
33  for(DenseIndex i=poly.size()-2; i>=0; --i ){
34  val = val*x + poly[i]; }
35  return val;
36 }

◆ roots_to_monicPolynomial()

template<typename RootVector , typename Polynomial >
void Eigen::roots_to_monicPolynomial ( const RootVector &  rv,
Polynomial &  poly 
)

Given the roots of a polynomial compute the coefficients in the monomial basis of the monic polynomial with same roots and minimal degree. If RootVector is a vector of complexes, Polynomial should also be a vector of complexes.

Parameters
[in]rv: a vector containing the roots of a polynomial.
[out]poly: the vector of coefficients of the polynomial ordered by degrees i.e. poly[i] is the coefficient of degree i of the polynomial e.g. \( 3 + x^2 \) is stored as a vector \( [ 3, 0, 1 ] \).

Definition at line 129 of file PolynomialUtils.h.

130 {
131 
132  typedef typename Polynomial::Scalar Scalar;
133 
134  poly.setZero( rv.size()+1 );
135  poly[0] = -rv[0]; poly[1] = Scalar(1);
136  for( DenseIndex i=1; i< rv.size(); ++i )
137  {
138  for( DenseIndex j=i+1; j>0; --j ){ poly[j] = poly[j-1] - rv[i]*poly[j]; }
139  poly[0] = -rv[i]*poly[0];
140  }
141 }