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

Defined to be inherited by polynomial solvers: it provides convenient methods such as. More...

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

Public Types

typedef DenseIndex Index
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef Matrix< RootType, Deg_, 1 > RootsType
 
typedef std::complex< RealScalarRootType
 
typedef Scalar_ Scalar
 

Public Member Functions

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 RootTypegreatestRoot () const
 
 PolynomialSolverBase ()
 
template<typename OtherPolynomial >
 PolynomialSolverBase (const OtherPolynomial &poly)
 
template<typename Stl_back_insertion_sequence >
void realRoots (Stl_back_insertion_sequence &bi_seq, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RootsTyperoots () const
 
const RealScalarsmallestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RootTypesmallestRoot () const
 

Protected Member Functions

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
 
template<typename OtherPolynomial >
void setPolynomial (const OtherPolynomial &poly)
 

Protected Attributes

RootsType m_roots
 

Detailed Description

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

Defined to be inherited by polynomial solvers: it provides convenient methods such as.

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

It stores the set of roots as a vector of complexes.

Definition at line 31 of file PolynomialSolver.h.

Member Typedef Documentation

◆ Index

template<typename Scalar_ , int Deg_>
typedef DenseIndex Eigen::PolynomialSolverBase< Scalar_, Deg_ >::Index

Definition at line 41 of file PolynomialSolver.h.

◆ RealScalar

template<typename Scalar_ , int Deg_>
typedef NumTraits<Scalar>::Real Eigen::PolynomialSolverBase< Scalar_, Deg_ >::RealScalar

Definition at line 37 of file PolynomialSolver.h.

◆ RootsType

template<typename Scalar_ , int Deg_>
typedef Matrix<RootType,Deg_,1> Eigen::PolynomialSolverBase< Scalar_, Deg_ >::RootsType

Definition at line 39 of file PolynomialSolver.h.

◆ RootType

template<typename Scalar_ , int Deg_>
typedef std::complex<RealScalar> Eigen::PolynomialSolverBase< Scalar_, Deg_ >::RootType

Definition at line 38 of file PolynomialSolver.h.

◆ Scalar

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

Definition at line 36 of file PolynomialSolver.h.

Constructor & Destructor Documentation

◆ PolynomialSolverBase() [1/2]

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

Definition at line 50 of file PolynomialSolver.h.

50  {
51  setPolynomial( poly() ); }
void setPolynomial(const OtherPolynomial &poly)

◆ PolynomialSolverBase() [2/2]

template<typename Scalar_ , int Deg_>
Eigen::PolynomialSolverBase< Scalar_, Deg_ >::PolynomialSolverBase ( )
inline

Definition at line 53 of file PolynomialSolver.h.

53 {}

Member Function Documentation

◆ absGreatestRealRoot()

template<typename Scalar_ , int Deg_>
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::absGreatestRealRoot ( bool &  hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
a real root with greatest absolute magnitude. A real root is defined as the real part of a complex root with absolute imaginary part smallest than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value. If no real root is found the boolean hasArealRoot is set to false and the real part of the root with smallest absolute imaginary part is returned instead.
Parameters
[out]hasArealRoot: boolean true if a real root is found according to the absImaginaryThreshold criterion, false otherwise.
[in]absImaginaryThreshold: threshold on the absolute imaginary part to decide whether or not a root is real.

Definition at line 214 of file PolynomialSolver.h.

217  {
218  std::greater<RealScalar> greater;
219  return selectRealRoot_withRespectToAbsRealPart( greater, hasArealRoot, absImaginaryThreshold );
220  }
const RealScalar & selectRealRoot_withRespectToAbsRealPart(squaredRealPartBinaryPredicate &pred, bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const

◆ absSmallestRealRoot()

template<typename Scalar_ , int Deg_>
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::absSmallestRealRoot ( bool &  hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
a real root with smallest absolute magnitude. A real root is defined as the real part of a complex root with absolute imaginary part smallest than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value. If no real root is found the boolean hasArealRoot is set to false and the real part of the root with smallest absolute imaginary part is returned instead.
Parameters
[out]hasArealRoot: boolean true if a real root is found according to the absImaginaryThreshold criterion, false otherwise.
[in]absImaginaryThreshold: threshold on the absolute imaginary part to decide whether or not a root is real.

Definition at line 237 of file PolynomialSolver.h.

240  {
241  std::less<RealScalar> less;
242  return selectRealRoot_withRespectToAbsRealPart( less, hasArealRoot, absImaginaryThreshold );
243  }

◆ greatestRealRoot()

template<typename Scalar_ , int Deg_>
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::greatestRealRoot ( bool &  hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
the real root with greatest value. A real root is defined as the real part of a complex root with absolute imaginary part smallest than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value. If no real root is found the boolean hasArealRoot is set to false and the real part of the root with smallest absolute imaginary part is returned instead.
Parameters
[out]hasArealRoot: boolean true if a real root is found according to the absImaginaryThreshold criterion, false otherwise.
[in]absImaginaryThreshold: threshold on the absolute imaginary part to decide whether or not a root is real.

Definition at line 260 of file PolynomialSolver.h.

263  {
264  std::greater<RealScalar> greater;
265  return selectRealRoot_withRespectToRealPart( greater, hasArealRoot, absImaginaryThreshold );
266  }
const RealScalar & selectRealRoot_withRespectToRealPart(RealPartBinaryPredicate &pred, bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const

◆ greatestRoot()

template<typename Scalar_ , int Deg_>
const RootType& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::greatestRoot ( ) const
inline
Returns
the complex root with greatest norm.

Definition at line 102 of file PolynomialSolver.h.

103  {
104  std::greater<RealScalar> greater;
105  return selectComplexRoot_withRespectToNorm( greater );
106  }
const RootType & selectComplexRoot_withRespectToNorm(squaredNormBinaryPredicate &pred) const

◆ realRoots()

template<typename Scalar_ , int Deg_>
template<typename Stl_back_insertion_sequence >
void Eigen::PolynomialSolverBase< Scalar_, Deg_ >::realRoots ( Stl_back_insertion_sequence &  bi_seq,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline

Clear and fills the back insertion sequence with the real roots of the polynomial i.e. the real part of the complex roots that have an imaginary part which absolute value is smaller than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value.

Parameters
[out]bi_seq: the back insertion sequence (stl concept)
[in]absImaginaryThreshold: the maximum bound of the imaginary part of a complex number that is considered as real.

Definition at line 71 of file PolynomialSolver.h.

73  {
74  using std::abs;
75  bi_seq.clear();
76  for(Index i=0; i<m_roots.size(); ++i )
77  {
78  if( abs( m_roots[i].imag() ) < absImaginaryThreshold ){
79  bi_seq.push_back( m_roots[i].real() ); }
80  }
81  }
int i
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_imag_op< typename Derived::Scalar >, const Derived > imag(const Eigen::ArrayBase< Derived > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_real_op< typename Derived::Scalar >, const Derived > real(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
adouble abs(const adouble &x)
Definition: AdolcForward:74

◆ roots()

template<typename Scalar_ , int Deg_>
const RootsType& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::roots ( ) const
inline
Returns
the complex roots of the polynomial

Definition at line 57 of file PolynomialSolver.h.

57 { return m_roots; }

◆ selectComplexRoot_withRespectToNorm()

template<typename Scalar_ , int Deg_>
template<typename squaredNormBinaryPredicate >
const RootType& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectComplexRoot_withRespectToNorm ( squaredNormBinaryPredicate &  pred) const
inlineprotected

Definition at line 85 of file PolynomialSolver.h.

86  {
87  Index res=0;
88  RealScalar norm2 = numext::abs2( m_roots[0] );
89  for( Index i=1; i<m_roots.size(); ++i )
90  {
91  const RealScalar currNorm2 = numext::abs2( m_roots[i] );
92  if( pred( currNorm2, norm2 ) ){
93  res=i; norm2=currNorm2; }
94  }
95  return m_roots[res];
96  }
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
NumTraits< Scalar >::Real RealScalar
bool abs2(bool x)

◆ selectRealRoot_withRespectToAbsRealPart()

template<typename Scalar_ , int Deg_>
template<typename squaredRealPartBinaryPredicate >
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectRealRoot_withRespectToAbsRealPart ( squaredRealPartBinaryPredicate &  pred,
bool &  hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inlineprotected

Definition at line 119 of file PolynomialSolver.h.

123  {
124  using std::abs;
125  hasArealRoot = false;
126  Index res=0;
127  RealScalar abs2(0);
128 
129  for( Index i=0; i<m_roots.size(); ++i )
130  {
131  if( abs( m_roots[i].imag() ) <= absImaginaryThreshold )
132  {
133  if( !hasArealRoot )
134  {
135  hasArealRoot = true;
136  res = i;
137  abs2 = m_roots[i].real() * m_roots[i].real();
138  }
139  else
140  {
141  const RealScalar currAbs2 = m_roots[i].real() * m_roots[i].real();
142  if( pred( currAbs2, abs2 ) )
143  {
144  abs2 = currAbs2;
145  res = i;
146  }
147  }
148  }
149  else if(!hasArealRoot)
150  {
151  if( abs( m_roots[i].imag() ) < abs( m_roots[res].imag() ) ){
152  res = i;}
153  }
154  }
155  return numext::real_ref(m_roots[res]);
156  }
internal::add_const_on_value_type_t< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) > real_ref(const Scalar &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs2_op< typename Derived::Scalar >, const Derived > abs2(const Eigen::ArrayBase< Derived > &x)

◆ selectRealRoot_withRespectToRealPart()

template<typename Scalar_ , int Deg_>
template<typename RealPartBinaryPredicate >
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectRealRoot_withRespectToRealPart ( RealPartBinaryPredicate &  pred,
bool &  hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inlineprotected

Definition at line 160 of file PolynomialSolver.h.

164  {
165  using std::abs;
166  hasArealRoot = false;
167  Index res=0;
168  RealScalar val(0);
169 
170  for( Index i=0; i<m_roots.size(); ++i )
171  {
172  if( abs( m_roots[i].imag() ) <= absImaginaryThreshold )
173  {
174  if( !hasArealRoot )
175  {
176  hasArealRoot = true;
177  res = i;
178  val = m_roots[i].real();
179  }
180  else
181  {
182  const RealScalar curr = m_roots[i].real();
183  if( pred( curr, val ) )
184  {
185  val = curr;
186  res = i;
187  }
188  }
189  }
190  else
191  {
192  if( abs( m_roots[i].imag() ) < abs( m_roots[res].imag() ) ){
193  res = i; }
194  }
195  }
196  return numext::real_ref(m_roots[res]);
197  }

◆ setPolynomial()

template<typename Scalar_ , int Deg_>
template<typename OtherPolynomial >
void Eigen::PolynomialSolverBase< Scalar_, Deg_ >::setPolynomial ( const OtherPolynomial &  poly)
inlineprotected

Definition at line 45 of file PolynomialSolver.h.

45  {
46  m_roots.resize(poly.size()-1); }
constexpr void resize(Index rows, Index cols)

◆ smallestRealRoot()

template<typename Scalar_ , int Deg_>
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::smallestRealRoot ( bool &  hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
the real root with smallest value. A real root is defined as the real part of a complex root with absolute imaginary part smallest than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value. If no real root is found the boolean hasArealRoot is set to false and the real part of the root with smallest absolute imaginary part is returned instead.
Parameters
[out]hasArealRoot: boolean true if a real root is found according to the absImaginaryThreshold criterion, false otherwise.
[in]absImaginaryThreshold: threshold on the absolute imaginary part to decide whether or not a root is real.

Definition at line 283 of file PolynomialSolver.h.

286  {
287  std::less<RealScalar> less;
288  return selectRealRoot_withRespectToRealPart( less, hasArealRoot, absImaginaryThreshold );
289  }

◆ smallestRoot()

template<typename Scalar_ , int Deg_>
const RootType& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::smallestRoot ( ) const
inline
Returns
the complex root with smallest norm.

Definition at line 111 of file PolynomialSolver.h.

112  {
113  std::less<RealScalar> less;
115  }

Member Data Documentation

◆ m_roots

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

Definition at line 292 of file PolynomialSolver.h.


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