Files Class List

Detailed Description

template<typename ftype, int N>
class cy::Polynomial< ftype, N >

A general-purpose polynomial class.

This class can be used for easily generating and manipulating polynomials. It also offers interfaces to the polynomial evaluation and root finding functions.

#include <cyPolynomial.h>

Public Member Functions

ftype const & operator[] (int i) const
 Access to the coefficients of the polynomial.
 
ftype & operator[] (int i)
 Access to the coefficients of the polynomial.
 
ftype operator() (ftype x) const
 Evaluates the polynomial at the given x value.
 
ftype Eval (ftype x) const
 Evaluates the polynomial at x.
 
ftype EvalWithDeriv (ftype &deriv, ftype x) const
 Evaluates the polynomial and its derivative at x.
 
Polynomial< ftype, N > operator+ (Polynomial< ftype, N > const &p) const
 Adds two polynomials.
 
Polynomial< ftype, N > operator- (Polynomial< ftype, N > const &p) const
 Subtracts two polynomials.
 
Polynomial< ftype, N > operator* (ftype s) const
 Multiplies the polynomial with a scalar.
 
void operator+= (Polynomial< ftype, N > const &p)
 Adds another polynomial to this one.
 
void operator-= (Polynomial< ftype, N > const &p)
 Subtracts another polynomial from this one.
 
void operator*= (ftype s)
 Multiplies this polynomial with a scalar.
 
template<int M>
Polynomial< ftype, N+M > operator* (Polynomial< ftype, M > const &p) const
 Multiplies two polynomials and returns the resulting polynomial.
 
Polynomial< ftype, 2 *N > Squared () const
 Multiplies the polynomial with itself and returns the resulting polynomial.
 
Polynomial< ftype, N-1 > Derivative () const
 Returns the derivative of the polynomial.
 
Polynomial< ftype, N-1 > Deflate (ftype root) const
 Returns the deflation of the polynomial with the given root.
 
Polynomial< ftype, N+1 > Inflate (ftype root) const
 Returns the inflated polynomial using the given root.
 
template<bool boundError = false>
int Roots (ftype roots[N], ftype xError=DefaultError()) const
 Finds all roots of the polynomial and returns the number of roots found.
 
template<bool boundError = false>
bool FirstRoot (ftype &root, ftype xError=DefaultError()) const
 Finds the first root of the polynomial and returns true if a root is found.
 
template<bool boundError = false>
bool HasRoot (ftype xError=DefaultError()) const
 Returns true if the polynomial has a root.
 
template<bool boundError = false, typename RootCallback >
void ForEachRoot (RootCallback c, ftype xError=DefaultError()) const
 Calls the given callback function for each root of the polynomial.
 
template<bool boundError = false>
int Roots (ftype roots[N], ftype xMin, ftype xMax, ftype xError=DefaultError()) const
 Finds all roots of the polynomial between xMin and xMax and returns the number of roots found.
 
template<bool boundError = false>
bool FirstRoot (ftype &root, ftype xMin, ftype xMax, ftype xError=DefaultError()) const
 Finds the first root of the polynomial between xMin and xMax and returns true if a root is found.
 
template<bool boundError = false>
bool HasRoot (ftype xMin, ftype xMax, ftype xError=DefaultError()) const
 Returns true if the polynomial has a root between xMin and xMax.
 
template<bool boundError = false, typename RootCallback >
void ForEachRoot (RootCallback c, ftype xMin, ftype xMax, ftype xError=DefaultError()) const
 Calls the given callback function for each root of the polynomial between xMin and xMax.
 
bool IsFinite () const
 Returns true if all coefficients are finite real numbers.
 

Public Attributes

ftype coef [N+1]
 The coefficients of the polynomial.
 

Static Protected Member Functions

static ftype DefaultError ()
 Returns the default error threshold for numerical root finding.