iRoCS Toolbox  1.1.0
Public Member Functions | Static Public Member Functions
atb::Polynomial< CoeffT > Class Template Reference

The Polynomial class provides arithmetical operations with polynomials as well as a root finding algorithm. More...

#include <ATBPolynomial.hh>

Inheritance diagram for atb::Polynomial< CoeffT >:
Collaboration diagram for atb::Polynomial< CoeffT >:

Public Member Functions

 Polynomial ()
 Default constructor. More...
 
 Polynomial (const std::vector< CoeffT > &coeffs)
 Creates a new polynomial with the given coefficient vector. More...
 
 Polynomial (const Polynomial< CoeffT > &p)
 Copy constructor. More...
 
 ~Polynomial ()
 Destructor. More...
 
const CoeffT & coefficient (size_t i) const
 Read-Only accessor to the i'th polynomial coefficient. More...
 
CoeffT & coefficient (size_t i)
 Read/Write accessor to the i'th polynomial coefficient. More...
 
size_t degree () const
 Retrieve the degree of the polynomial. More...
 
Polynomial< CoeffT > derivative (size_t degree=1)
 Computes the n'th derivative of this polynomial. More...
 
Polynomial< CoeffT > indefiniteIntegral (size_t degree=1)
 Computes the n'th indefinite Integral of this polynomial. More...
 
bool operator!= (const Polynomial< CoeffT > &p)
 Comparison of the given polynomial with this polynomial. More...
 
template<typename DomainT >
CoeffT operator() (DomainT x) const
 Evaluates the polynomial at position x. More...
 
Polynomial< CoeffT > & operator*= (const Polynomial< CoeffT > &p)
 Multiplication assignment operator. More...
 
Polynomial< CoeffT > & operator*= (const CoeffT &alpha)
 Multiplication assignment operator. More...
 
Polynomial< CoeffT > & operator+= (const Polynomial< CoeffT > &p)
 Plus assignment operator. More...
 
Polynomial< CoeffT > operator- () const
 Unary minus operator. More...
 
Polynomial< CoeffT > & operator-= (const Polynomial< CoeffT > &p)
 Minus assignment operator. More...
 
Polynomial< CoeffT > & operator/= (const CoeffT &alpha)
 Division assignment operator. More...
 
Polynomial< CoeffT > & operator= (const Polynomial< CoeffT > &p)
 Copy assignment operator. More...
 
bool operator== (const Polynomial< CoeffT > &p)
 Comparison of the given polynomial with this polynomial. More...
 
std::vector< typename traits< CoeffT >::ComplexT > roots (bool polish=true, bool sort=false)
 Computes and returns the vector of zero crossings of the polynomial. More...
 

Static Public Member Functions

static Polynomial< CoeffT > hermite (int n, double sigma=1.0/std::sqrt(2.0))
 Get the normalized Hermite polynomial of given degree. More...
 
static Polynomial< CoeffT > const & one ()
 Get the neutral element for multiplication of the Polynomial ring. More...
 
static Polynomial< CoeffT > const & zero ()
 Get the neutral element for addition of the Polynomial ring. More...
 

Detailed Description

template<typename CoeffT>
class atb::Polynomial< CoeffT >

The Polynomial class provides arithmetical operations with polynomials as well as a root finding algorithm.

Basic operations with polynomials, like addition, multiplication, evaluation and root finding are implemented within this class. It additionally provides a pretty-printer to produce neat verbose polynomial expressions from a set of coefficients.

Definition at line 65 of file ATBPolynomial.hh.

Constructor & Destructor Documentation

◆ Polynomial() [1/3]

template<typename CoeffT>
atb::Polynomial< CoeffT >::Polynomial ( )

Default constructor.

All coefficients will be zero, yielding the constant zero function.

◆ Polynomial() [2/3]

template<typename CoeffT>
atb::Polynomial< CoeffT >::Polynomial ( const std::vector< CoeffT > &  coeffs)

Creates a new polynomial with the given coefficient vector.

Parameters
coeffsThe coefficient vector $\vec{c}$ to initialize the polynomial with. The polynomial will be evaluated as follows:

\[ p(x) = \sum_{i=0}^p c_i x^i \]

where $p$ is the polynomial degree.

◆ Polynomial() [3/3]

template<typename CoeffT>
atb::Polynomial< CoeffT >::Polynomial ( const Polynomial< CoeffT > &  p)

Copy constructor.

The coefficient vector will be trimmed removing leading zeros, so if you explicitely need to set the highest coefficients to zero using the read/write accessor, you can remove them with this constructor with some memory allocation overhead, though.

Parameters
pThe polynomial to copy

◆ ~Polynomial()

template<typename CoeffT>
atb::Polynomial< CoeffT >::~Polynomial ( )

Destructor.

Member Function Documentation

◆ operator=()

template<typename CoeffT>
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator= ( const Polynomial< CoeffT > &  p)

Copy assignment operator.

The coefficient vector will be trimmed removing leading zeros, so if you explicitely need to set the highest coefficients to zero using the read/write accessor, you can remove them with this assignent operator with some memory allocation overhead, though.

Parameters
pThe polynomial to copy

◆ degree()

template<typename CoeffT>
size_t atb::Polynomial< CoeffT >::degree ( ) const

Retrieve the degree of the polynomial.

Returns
The polynomial degree

◆ coefficient() [1/2]

template<typename CoeffT>
const CoeffT& atb::Polynomial< CoeffT >::coefficient ( size_t  i) const

Read-Only accessor to the i'th polynomial coefficient.

Parameters
iThe index of the coefficient to retrieve
Returns
A const reference to the coefficient at index i

◆ coefficient() [2/2]

template<typename CoeffT>
CoeffT& atb::Polynomial< CoeffT >::coefficient ( size_t  i)

Read/Write accessor to the i'th polynomial coefficient.

If an index above the polynomial degree is requested the coefficient vector will be resized to fit all coefficients including the requested one. This may also have an impact on the degree() method, which has to search the highest non-zero coefficient for degree computation. Avoid adding leading zero coefficients, if they result from a computation they will be trimmed, but if you explicitely set them to zero using this accessor, the class cannot recognize it and degree computation, which is needed in other functions as well will be slow.

Parameters
iThe index of the coefficient to modify
Returns
A reference to the coefficient at index i

◆ operator()()

template<typename CoeffT>
template<typename DomainT >
CoeffT atb::Polynomial< CoeffT >::operator() ( DomainT  x) const

Evaluates the polynomial at position x.

Parameters
xThe position to evaluate the polynomial at
Returns
The function value at position x

◆ roots()

template<typename CoeffT>
std::vector<typename traits<CoeffT>::ComplexT> atb::Polynomial< CoeffT >::roots ( bool  polish = true,
bool  sort = false 
)

Computes and returns the vector of zero crossings of the polynomial.

Any polynomial of degree $p$ has $p$ complex roots, which are computed and returned by this function.

Parameters
polishThe found roots will be polished in a second pass to increase numerical precision
sortIf given the returned roots are ordered by increasing real part
Returns
A vector containing the complex roots of the polynomial

◆ derivative()

template<typename CoeffT>
Polynomial<CoeffT> atb::Polynomial< CoeffT >::derivative ( size_t  degree = 1)

Computes the n'th derivative of this polynomial.

Parameters
degreeThe degree of the derivative
Returns
The n'th derivative polynomial

◆ indefiniteIntegral()

template<typename CoeffT>
Polynomial<CoeffT> atb::Polynomial< CoeffT >::indefiniteIntegral ( size_t  degree = 1)

Computes the n'th indefinite Integral of this polynomial.

Parameters
degreethe degree of the integral
Returns
The polynomial obtained after n integrations of this polynomial

◆ operator==()

template<typename CoeffT>
bool atb::Polynomial< CoeffT >::operator== ( const Polynomial< CoeffT > &  p)

Comparison of the given polynomial with this polynomial.

Parameters
pThe polynomial to compare this polynomial with
Returns
If all coefficients of the polynomials are identical true is returned, false otherwise.

◆ operator!=()

template<typename CoeffT>
bool atb::Polynomial< CoeffT >::operator!= ( const Polynomial< CoeffT > &  p)

Comparison of the given polynomial with this polynomial.

Parameters
pThe polynomial to compare this polynomial with
Returns
If all coefficients of the polynomials are different true is returned, false otherwise.

◆ operator-()

template<typename CoeffT>
Polynomial<CoeffT> atb::Polynomial< CoeffT >::operator- ( ) const

Unary minus operator.

Returns
A polynomial with all coefficients negated

◆ operator+=()

template<typename CoeffT>
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator+= ( const Polynomial< CoeffT > &  p)

Plus assignment operator.

Adds the given polynomial to this polynomial.

Parameters
pThe polynomial to add to this one
Returns
A reference to this polynomial for arithmetic chaining

◆ operator-=()

template<typename CoeffT>
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator-= ( const Polynomial< CoeffT > &  p)

Minus assignment operator.

Subtracts the given polynomial from this polynomial.

Parameters
pThe polynomial to subtract from this one
Returns
A reference to this polynomial for arithmetic chaining

◆ operator*=() [1/2]

template<typename CoeffT>
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator*= ( const Polynomial< CoeffT > &  p)

Multiplication assignment operator.

Multiplies the given polynomial to this polynomial.

Parameters
pThe polynomial to multiply to this one
Returns
A reference to this polynomial for arithmetic chaining

◆ operator*=() [2/2]

template<typename CoeffT>
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator*= ( const CoeffT &  alpha)

Multiplication assignment operator.

Multiplies the given scalar value to this polynomial.

Parameters
alphaThe scalar to multiply to this polynomial
Returns
A reference to this polynomial for arithmetic chaining

◆ operator/=()

template<typename CoeffT>
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator/= ( const CoeffT &  alpha)

Division assignment operator.

Divides this polynomial by the given scalar value.Multiplies the given scalar value.

Parameters
alphaThe scalar to divide this polynomial by
Returns
A reference to this polynomial for arithmetic chaining

◆ zero()

template<typename CoeffT>
static Polynomial<CoeffT> const& atb::Polynomial< CoeffT >::zero ( )
static

Get the neutral element for addition of the Polynomial ring.

Returns
The polynomial with all coefficients being zero

◆ one()

template<typename CoeffT>
static Polynomial<CoeffT> const& atb::Polynomial< CoeffT >::one ( )
static

Get the neutral element for multiplication of the Polynomial ring.

Returns
The polynomial with all coefficients equalling zero except for the zeroth equalling one

◆ hermite()

template<typename CoeffT>
static Polynomial<CoeffT> atb::Polynomial< CoeffT >::hermite ( int  n,
double  sigma = 1.0/std::sqrt(2.0) 
)
static

Get the normalized Hermite polynomial of given degree.

The normalized Hermite polynomials multiplied with a normal distribution result in the derivative of the normal distribution of corresponding degree. The normalized Hermite polynomials are recursively defined as follows:

\[ H_n^{\sigma}\left( x \right) := \left\{ \begin{array}{l@{\quad}l} 0 & n < 0 \\ 1 & n = 0 \\ \frac{1}{\sigma^2} x H_{n-1}^{\sigma}\left( x \right) - \frac{1}{\sigma^2} (n - 1) H_{n-2}^{\sigma}\left( x \right) & \textrm{otherwise} \end{array} \right. \]

Parameters
nThe polynomial degree
sigmaThe Standard deviation of the normal distribution to compute the derivative for
Returns
The normalized Hermite polynomial of degree n

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