iRoCS Toolbox
1.1.0
|
The Polynomial class provides arithmetical operations with polynomials as well as a root finding algorithm. More...
#include <ATBPolynomial.hh>
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... | |
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.
atb::Polynomial< CoeffT >::Polynomial | ( | ) |
Default constructor.
All coefficients will be zero, yielding the constant zero function.
atb::Polynomial< CoeffT >::Polynomial | ( | const std::vector< CoeffT > & | coeffs | ) |
Creates a new polynomial with the given coefficient vector.
coeffs | The coefficient vector ![]()
|
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.
p | The polynomial to copy |
atb::Polynomial< CoeffT >::~Polynomial | ( | ) |
Destructor.
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.
p | The polynomial to copy |
size_t atb::Polynomial< CoeffT >::degree | ( | ) | const |
Retrieve the degree of the polynomial.
const CoeffT& atb::Polynomial< CoeffT >::coefficient | ( | size_t | i | ) | const |
Read-Only accessor to the i'th polynomial coefficient.
i | The index of the coefficient to retrieve |
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.
i | The index of the coefficient to modify |
CoeffT atb::Polynomial< CoeffT >::operator() | ( | DomainT | x | ) | const |
Evaluates the polynomial at position x.
x | The position to evaluate the polynomial at |
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.
polish | The found roots will be polished in a second pass to increase numerical precision |
sort | If given the returned roots are ordered by increasing real part |
Polynomial<CoeffT> atb::Polynomial< CoeffT >::derivative | ( | size_t | degree = 1 | ) |
Computes the n'th derivative of this polynomial.
degree | The degree of the derivative |
Polynomial<CoeffT> atb::Polynomial< CoeffT >::indefiniteIntegral | ( | size_t | degree = 1 | ) |
Computes the n'th indefinite Integral of this polynomial.
degree | the degree of the integral |
bool atb::Polynomial< CoeffT >::operator== | ( | const Polynomial< CoeffT > & | p | ) |
Comparison of the given polynomial with this polynomial.
p | The polynomial to compare this polynomial with |
true
is returned, false
otherwise. bool atb::Polynomial< CoeffT >::operator!= | ( | const Polynomial< CoeffT > & | p | ) |
Comparison of the given polynomial with this polynomial.
p | The polynomial to compare this polynomial with |
true
is returned, false
otherwise. Polynomial<CoeffT> atb::Polynomial< CoeffT >::operator- | ( | ) | const |
Unary minus operator.
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator+= | ( | const Polynomial< CoeffT > & | p | ) |
Plus assignment operator.
Adds the given polynomial to this polynomial.
p | The polynomial to add to this one |
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator-= | ( | const Polynomial< CoeffT > & | p | ) |
Minus assignment operator.
Subtracts the given polynomial from this polynomial.
p | The polynomial to subtract from this one |
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator*= | ( | const Polynomial< CoeffT > & | p | ) |
Multiplication assignment operator.
Multiplies the given polynomial to this polynomial.
p | The polynomial to multiply to this one |
Polynomial<CoeffT>& atb::Polynomial< CoeffT >::operator*= | ( | const CoeffT & | alpha | ) |
Multiplication assignment operator.
Multiplies the given scalar value to this polynomial.
alpha | The scalar to multiply to this polynomial |
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.
alpha | The scalar to divide this polynomial by |
|
static |
Get the neutral element for addition of the Polynomial ring.
|
static |
Get the neutral element for multiplication of the Polynomial ring.
|
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:
n | The polynomial degree |
sigma | The Standard deviation of the normal distribution to compute the derivative for |