Public Member Functions | Protected Attributes | List of all members
vnl_polynomial< T > Class Template Reference

Evaluation of polynomials. More...

#include <vnl_polynomial.h>

Public Member Functions

 vnl_polynomial (std::vector< T > const &a)
 Initialize the polynomial from its coefficients, lowest order first. More...
 
 vnl_polynomial (T const *a, unsigned len)
 Initialize polynomial from C array, highest order first. More...
 
 vnl_polynomial (T const &a)
 Initialize polynomial from single value, thus creating a monomial. More...
 
 vnl_polynomial (int d=-1)
 Initialize polynomial of a given degree. More...
 
bool operator== (vnl_polynomial< T > const &p) const
 comparison operator. More...
 
vnl_polynomial< T > operator- () const
 Returns negative of this polynomial. More...
 
vnl_polynomial< T > operator+ (vnl_polynomial< T > const &f) const
 Returns polynomial which is sum of this with polynomial f. More...
 
vnl_polynomial< T > operator- (vnl_polynomial< T > const &f) const
 Returns polynomial which is difference of this with polynomial f. More...
 
vnl_polynomial< T > operator * (vnl_polynomial< T > const &f) const
 Returns polynomial which is product of this with polynomial f. More...
 
vnl_polynomial< T > operator/ (vnl_polynomial< T > const &f) const
 Returns polynomial which is the result of the long division by polynomial f. More...
 
vnl_polynomial< T > operator% (vnl_polynomial< T > const &f) const
 Returns polynomial which is the remainder after a long division by polynomial f. More...
 
vnl_polynomial< T > & operator+= (vnl_polynomial< T > const &f)
 
vnl_polynomial< T > & operator-= (vnl_polynomial< T > const &f)
 
vnl_polynomial< T > & operator *= (vnl_polynomial< T > const &f)
 
vnl_polynomial< T > & operator/= (vnl_polynomial< T > const &f)
 
vnl_polynomial< T > & operator%= (vnl_polynomial< T > const &f)
 
evaluate (T const &x) const
 Evaluate polynomial at value x. More...
 
vnl_polynomial< T > derivative () const
 Return derivative of this polynomial. More...
 
devaluate (T const &x) const
 Evaluate derivative at value x. More...
 
vnl_polynomial< T > primitive () const
 Return primitive function (inverse derivative) of this polynomial. More...
 
evaluate_integral (T const &x) const
 Evaluate integral at x (assuming constant of integration is zero). More...
 
evaluate_integral (T const &x1, T const &x2) const
 Evaluate integral between x1 and x2. More...
 
int degree () const
 Return the degree (highest power of X) of the polynomial. More...
 
T & operator [] (unsigned int i)
 Access to the polynomial coefficient of $X^i$. More...
 
operator [] (unsigned int i) const
 Access to the polynomial coefficient of $X^i$. More...
 
const std::vector< T > & coefficients () const
 Return the vector of coefficients. More...
 
std::vector< T > & coefficients ()
 Return the vector of coefficients. More...
 
void set_coefficients (std::vector< T > const &coeffs)
 
void print (std::ostream &os) const
 Print this polynomial to stream. More...
 

Protected Attributes

std::vector< T > coeffs_
 The coefficients of the polynomial. More...
 

Detailed Description

template<class T>
class vnl_polynomial< T >

Evaluation of polynomials.

vnl_polynomial<T> represents a univariate polynomial with coefficients of datatype T, stored as a vector of values. This allows evaluation of the polynomial $p(X)$ at given values of $X$, and of its derivative $p'(X)$ or primitive function $\int p$.

The class also provides the common polynomial arithmetic, i.e.,

The coefficients (coeffs_) are stored as a vector, starting with the constant term. Hence coeffs_[n] is the coefficient of $X^n$,

Definition at line 53 of file vnl_polynomial.h.

Constructor & Destructor Documentation

◆ vnl_polynomial() [1/4]

template<class T>
vnl_polynomial< T >::vnl_polynomial ( std::vector< T > const &  a)
inline

Initialize the polynomial from its coefficients, lowest order first.

The polynomial is $ a[d] X^d + a[d-1] X^{d-1} + \cdots + a[0] = 0 $. Note that this constructor expects the constant term coefficient first, as opposed to the C array constructor! An assertion makes sure that the input vector is in normalised form, i.e., that it is either empty or that the highest order coefficient is nonzero.

Definition at line 62 of file vnl_polynomial.h.

◆ vnl_polynomial() [2/4]

template<class T>
vnl_polynomial< T >::vnl_polynomial ( T const *  a,
unsigned  len 
)
inline

Initialize polynomial from C array, highest order first.

The parameter len is the number of coefficients passed in, which equals the degree plus one. Note that this constructor expects the highest order coefficients first, as opposed to the std::vector constructor!

Definition at line 69 of file vnl_polynomial.h.

◆ vnl_polynomial() [3/4]

template<class T>
vnl_polynomial< T >::vnl_polynomial ( T const &  a)
inline

Initialize polynomial from single value, thus creating a monomial.

This is effectively an implicit cast from type T to class vnl_polynomial, useful when adding or multiplying a polynomial with a number.

Definition at line 74 of file vnl_polynomial.h.

◆ vnl_polynomial() [4/4]

template<class T>
vnl_polynomial< T >::vnl_polynomial ( int  d = -1)
inline

Initialize polynomial of a given degree.

The default constructor initializes to the zero polynomial (which has degree -1). but even with an explicit argument, the polynomial is the zero polynomial (with non-compact storage) so it should always be used in conjunction with operator[] for setting individual coefficients, at least coefficient [d].

Definition at line 81 of file vnl_polynomial.h.

Member Function Documentation

◆ coefficients() [1/2]

template<class T>
const std::vector<T>& vnl_polynomial< T >::coefficients ( ) const
inline

Return the vector of coefficients.

Definition at line 151 of file vnl_polynomial.h.

◆ coefficients() [2/2]

template<class T>
std::vector<T>& vnl_polynomial< T >::coefficients ( )
inline

Return the vector of coefficients.

Definition at line 153 of file vnl_polynomial.h.

◆ degree()

template<class T>
int vnl_polynomial< T >::degree ( ) const
inline

Return the degree (highest power of X) of the polynomial.

If the polynomial is zero, the degree is effectively -1. Note that this method assumes a compactified representation, i.e., one where the highest order coefficient is non-zero. Otherwise, the value returned by degree() will be larger than the degree.

Definition at line 143 of file vnl_polynomial.h.

◆ derivative()

template<class T >
vnl_polynomial< T > vnl_polynomial< T >::derivative ( ) const

Return derivative of this polynomial.

Definition at line 109 of file vnl_polynomial.hxx.

◆ devaluate()

template<class T>
T vnl_polynomial< T >::devaluate ( T const &  x) const
inline

Evaluate derivative at value x.

Definition at line 121 of file vnl_polynomial.h.

◆ evaluate()

template<class T >
T vnl_polynomial< T >::evaluate ( T const &  x) const

Evaluate polynomial at value x.

Evaluate polynomial at value x.

Definition at line 22 of file vnl_polynomial.hxx.

◆ evaluate_integral() [1/2]

template<class T>
T vnl_polynomial< T >::evaluate_integral ( T const &  x) const
inline

Evaluate integral at x (assuming constant of integration is zero).

Beware that this operation might not make sense for integral types T!

Definition at line 130 of file vnl_polynomial.h.

◆ evaluate_integral() [2/2]

template<class T>
T vnl_polynomial< T >::evaluate_integral ( T const &  x1,
T const &  x2 
) const
inline

Evaluate integral between x1 and x2.

Beware that this operation might not make sense for integral types T!

Definition at line 134 of file vnl_polynomial.h.

◆ operator *()

template<class T >
vnl_polynomial< T > vnl_polynomial< T >::operator * ( vnl_polynomial< T > const &  f) const

Returns polynomial which is product of this with polynomial f.

Definition at line 61 of file vnl_polynomial.hxx.

◆ operator *=()

template<class T>
vnl_polynomial<T>& vnl_polynomial< T >::operator *= ( vnl_polynomial< T > const &  f)
inline

Definition at line 110 of file vnl_polynomial.h.

◆ operator []() [1/2]

template<class T>
T& vnl_polynomial< T >::operator [] ( unsigned int  i)
inline

Access to the polynomial coefficient of $X^i$.

Definition at line 146 of file vnl_polynomial.h.

◆ operator []() [2/2]

template<class T>
T vnl_polynomial< T >::operator [] ( unsigned int  i) const
inline

Access to the polynomial coefficient of $X^i$.

Definition at line 148 of file vnl_polynomial.h.

◆ operator%()

template<class T >
vnl_polynomial< T > vnl_polynomial< T >::operator% ( vnl_polynomial< T > const &  f) const

Returns polynomial which is the remainder after a long division by polynomial f.

Returns polynomial which is the remainder after long division by f.

Beware that this operation might not make sense for integral types T if the highest order coefficient of f is not 1 or -1!

Definition at line 94 of file vnl_polynomial.hxx.

◆ operator%=()

template<class T>
vnl_polynomial<T>& vnl_polynomial< T >::operator%= ( vnl_polynomial< T > const &  f)
inline

Definition at line 112 of file vnl_polynomial.h.

◆ operator+()

template<class T >
vnl_polynomial< T > vnl_polynomial< T >::operator+ ( vnl_polynomial< T > const &  f) const

Returns polynomial which is sum of this with polynomial f.

Definition at line 47 of file vnl_polynomial.hxx.

◆ operator+=()

template<class T>
vnl_polynomial<T>& vnl_polynomial< T >::operator+= ( vnl_polynomial< T > const &  f)
inline

Definition at line 108 of file vnl_polynomial.h.

◆ operator-() [1/2]

template<class T >
vnl_polynomial< T > vnl_polynomial< T >::operator- ( ) const

Returns negative of this polynomial.

Definition at line 37 of file vnl_polynomial.hxx.

◆ operator-() [2/2]

template<class T>
vnl_polynomial<T> vnl_polynomial< T >::operator- ( vnl_polynomial< T > const &  f) const
inline

Returns polynomial which is difference of this with polynomial f.

Definition at line 93 of file vnl_polynomial.h.

◆ operator-=()

template<class T>
vnl_polynomial<T>& vnl_polynomial< T >::operator-= ( vnl_polynomial< T > const &  f)
inline

Definition at line 109 of file vnl_polynomial.h.

◆ operator/()

template<class T >
vnl_polynomial< T > vnl_polynomial< T >::operator/ ( vnl_polynomial< T > const &  f) const

Returns polynomial which is the result of the long division by polynomial f.

Returns polynomial which is the result of a long division by f.

Beware that this operation might not make sense for integral types T if the highest order coefficient of f is not 1 or -1!

Definition at line 76 of file vnl_polynomial.hxx.

◆ operator/=()

template<class T>
vnl_polynomial<T>& vnl_polynomial< T >::operator/= ( vnl_polynomial< T > const &  f)
inline

Definition at line 111 of file vnl_polynomial.h.

◆ operator==()

template<class T>
bool vnl_polynomial< T >::operator== ( vnl_polynomial< T > const &  p) const
inline

comparison operator.

Definition at line 84 of file vnl_polynomial.h.

◆ primitive()

template<class T >
vnl_polynomial< T > vnl_polynomial< T >::primitive ( ) const

Return primitive function (inverse derivative) of this polynomial.

Since a primitive function is not unique, the one with constant term 0 is returned. Beware that this operation might not make sense for integral types T!

Since a primitive function is not unique, the one with constant = 0 is returned Beware that this operation might not make sense for integral types T!

Definition at line 123 of file vnl_polynomial.hxx.

◆ print()

template<class T >
void vnl_polynomial< T >::print ( std::ostream &  os) const

Print this polynomial to stream.

Definition at line 135 of file vnl_polynomial.hxx.

◆ set_coefficients()

template<class T>
void vnl_polynomial< T >::set_coefficients ( std::vector< T > const &  coeffs)
inline

Definition at line 155 of file vnl_polynomial.h.

Member Data Documentation

◆ coeffs_

template<class T>
std::vector<T> vnl_polynomial< T >::coeffs_
protected

The coefficients of the polynomial.

coeffs_.front() is the const term. coeffs_[n] is the coefficient of the $X^n$ term

Definition at line 164 of file vnl_polynomial.h.


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