Simpatico  v1.10
List of all members | Static Public Member Functions
Util::Polynomial< T > Class Template Reference

Detailed Description

template<typename T = Rational>
class Util::Polynomial< T >

A Polynomial (i.e,.

a list of coefficents).

Definition at line 30 of file Polynomial.h.

#include <Polynomial.h>

Inheritance diagram for Util::Polynomial< T >:
Util::GArray< T >

Public Member Functions

Constructors, Destructors, and Assignment
 Polynomial (int capacity=10)
 Construct a zero polynomial. More...
 
 Polynomial (T c)
 Construct a constant polynomial. More...
 
 Polynomial (Array< T > const &coeffs)
 Construct a polynomial from array of coefficients. More...
 
 Polynomial (Polynomial< T > const &other)
 Copy constructor. More...
 
template<typename U >
Polynomial< T > & operator= (Polynomial< U > const &other)
 Assignment from another polynomial. More...
 
void setToZero ()
 Assign this polynomial a value of zero. More...
 
Simple Accessors
int degree () const
 Return degree of polynomial. More...
 
Arithmetic Assignment Operators
Polynomial< T > & operator+= (const Polynomial< T > &a)
 Add another polynomial to this one. More...
 
Polynomial< T > & operator+= (T a)
 Add a constant to this polynomial. More...
 
Polynomial< T > & operator-= (const Polynomial< T > &a)
 Subtract another polynomial from this one. More...
 
Polynomial< T > & operator-= (T a)
 Subtract a constant from this polynomial. More...
 
Polynomial< T > & operator*= (T a)
 Multiply this polynomial by a scalar. More...
 
Polynomial< T > & operator/= (T a)
 Divide this polynomial by a scalar. More...
 
Polynomial< T > & operator*= (const Polynomial< T > &a)
 Multiply this polynomial by another. More...
 
Mathematical Functions (return polynomials)
Polynomial< T > integrate () const
 Compute and return indefinite integral of this polynomial. More...
 
Polynomial< T > differentiate () const
 Compute and return derivative of this polynomial. More...
 
Polynomial< T > reflect () const
 Compute and return reflected polynomial f(-x). More...
 
Polynomial< T > shift (T a) const
 Compute and return shifted polynomial f(x+a). More...
 
Polynomial Evaluation Functions
operator() (T x) const
 Evaluate polynomial at specific argument of type T. More...
 
double evaluate (double x) const
 Evaluate polynomial at specific floating point argument. More...
 

Static Public Member Functions

static Polynomial< T > monomial (int n)
 Return a monomial f(x) = x^{n}. More...
 

Constructor & Destructor Documentation

template<typename T >
Util::Polynomial< T >::Polynomial ( int  capacity = 10)
inline

Construct a zero polynomial.

Creates a zero polynomial f(x) = 0, with no stored coefficients. The capacity parameter specifies how much physical space to allocate for subsqequent growth in the array of coefficients.

Parameters
capacityinitial capacity of coefficient array.

Definition at line 264 of file Polynomial.h.

References Util::GArray< Data >::reserve().

template<typename T>
Util::Polynomial< T >::Polynomial ( c)
inlineexplicit

Construct a constant polynomial.

Creates a polynomial f(x) = c, with degree() = 0.

Parameters
cconstant coefficient value

Definition at line 272 of file Polynomial.h.

References Util::GArray< Data >::append(), and Util::GArray< Data >::reserve().

template<typename T>
Util::Polynomial< T >::Polynomial ( Array< T > const &  coeffs)
inline

Construct a polynomial from array of coefficients.

Constructs a polynomial in which the coefficient of x^{i} is given by coeffs[i]. The logical and physical size of the coefficient array are both set to the capacity of coeffs.

Parameters
coeffsarray of coefficients.

Definition at line 283 of file Polynomial.h.

References Util::GArray< Data >::append(), Util::Array< Data >::capacity(), and Util::GArray< Data >::reserve().

template<typename T>
Util::Polynomial< T >::Polynomial ( Polynomial< T > const &  other)
inline

Member Function Documentation

template<typename T = Rational>
template<typename U >
Polynomial<T>& Util::Polynomial< T >::operator= ( Polynomial< U > const &  other)

Assignment from another polynomial.

Parameters
otherPolynomial to assign.

Referenced by Util::Polynomial< T >::Polynomial().

template<typename T >
void Util::Polynomial< T >::setToZero ( )
inline

Assign this polynomial a value of zero.

Equivalent to GArray::clear(): Clears all coefficients, setting size = 0 and degree = -1.

Definition at line 335 of file Polynomial.h.

References Util::GArray< Data >::clear().

Referenced by Util::Polynomial< T >::differentiate(), Util::Polynomial< T >::integrate(), Util::Polynomial< T >::operator*=(), and Util::Polynomial< T >::Polynomial().

template<typename T >
int Util::Polynomial< T >::degree ( ) const
inline

Return degree of polynomial.

Returns size() - 1, number of coefficients - 1. By convention, a zero polynomial has degree = -1.

Definition at line 343 of file Polynomial.h.

References Util::GArray< Data >::size().

Referenced by Util::Polynomial< T >::evaluate(), Util::Polynomial< T >::operator()(), and Util::Polynomial< T >::shift().

template<typename T>
Polynomial< T > & Util::Polynomial< T >::operator+= ( const Polynomial< T > &  a)

Add another polynomial to this one.

Upon return, *this = this + a.

Parameters
aincrement (input)

Definition at line 350 of file Polynomial.h.

References Util::GArray< Data >::append(), Util::GArray< T >::size(), and UTIL_CHECK.

template<typename T>
Polynomial< T > & Util::Polynomial< T >::operator+= ( a)

Add a constant to this polynomial.

Upon return, *this = this + a.

Parameters
aincrement (input)

Definition at line 373 of file Polynomial.h.

References Util::GArray< T >::size().

template<typename T>
Polynomial< T > & Util::Polynomial< T >::operator-= ( const Polynomial< T > &  a)

Subtract another polynomial from this one.

Upon return, *this = this + a.

Parameters
adecrement (input)

Definition at line 387 of file Polynomial.h.

References Util::GArray< Data >::append(), Util::GArray< T >::size(), and UTIL_CHECK.

template<typename T>
Polynomial< T > & Util::Polynomial< T >::operator-= ( a)

Subtract a constant from this polynomial.

Upon return, *this = this + a.

Parameters
aincrement (input)

Definition at line 410 of file Polynomial.h.

References Util::GArray< T >::size().

template<typename T>
Polynomial< T > & Util::Polynomial< T >::operator*= ( a)
inline

Multiply this polynomial by a scalar.

Upon return, *this = this*a.

Parameters
ascalar factor

Definition at line 425 of file Polynomial.h.

References Util::GArray< T >::size().

template<typename T>
Polynomial< T > & Util::Polynomial< T >::operator/= ( a)
inline

Divide this polynomial by a scalar.

Upon return, *this = this*a.

Parameters
ascalar factor (input)

Definition at line 440 of file Polynomial.h.

References Util::GArray< T >::size().

template<typename T>
Polynomial< T > & Util::Polynomial< T >::operator*= ( const Polynomial< T > &  a)

Multiply this polynomial by another.

Upon return, *this = this*a.

Parameters
aincrement (input)

Definition at line 454 of file Polynomial.h.

References Util::GArray< Data >::append(), Util::GArray< T >::capacity(), Util::GArray< Data >::reserve(), Util::Polynomial< T >::setToZero(), Util::GArray< T >::size(), Util::GArray< Data >::size(), and UTIL_ASSERT.

template<typename T >
Polynomial< T > Util::Polynomial< T >::integrate ( ) const

Compute and return indefinite integral of this polynomial.

Returns an indefinite integral with zero constant term.

Returns
indefinite integral polynomial.

Definition at line 502 of file Polynomial.h.

References Util::DArray< Data >::allocate(), Util::Polynomial< T >::setToZero(), and Util::GArray< T >::size().

template<typename T >
Polynomial< T > Util::Polynomial< T >::differentiate ( ) const

Compute and return derivative of this polynomial.

Returns a polynomial of one smaller degree.

Returns
derivative polynomial

Definition at line 528 of file Polynomial.h.

References Util::DArray< Data >::allocate(), Util::Polynomial< T >::setToZero(), and Util::GArray< T >::size().

template<typename T >
Polynomial< T > Util::Polynomial< T >::reflect ( ) const

Compute and return reflected polynomial f(-x).

If this polynomial is f(x), this returns a polynomial g(x) = f(-x) created by the reflection operation x-> -x. This yields a polynomial in which the sign is reversed for all coefficients of odd powers of x.

Returns
polynomial created by reflection x -> -x.

Definition at line 557 of file Polynomial.h.

References Util::GArray< T >::size().

template<typename T>
Polynomial< T > Util::Polynomial< T >::shift ( a) const

Compute and return shifted polynomial f(x+a).

If this polynomial is f(x), this returns a polynomial g(x) = f(x+a) created by the shift operation x-> x + a.

Returns
polynomial created by shift operation x -> x + a.

Definition at line 576 of file Polynomial.h.

References Util::Binomial::coeff(), Util::Polynomial< T >::degree(), Util::Binomial::setup(), and Util::GArray< T >::size().

template<typename T>
T Util::Polynomial< T >::operator() ( x) const
inline

Evaluate polynomial at specific argument of type T.

Parameters
xvalue of argument
Returns
Value f(x) of this polynomial at specified x

Definition at line 602 of file Polynomial.h.

References Util::Polynomial< T >::degree(), and Util::GArray< T >::size().

template<typename T >
double Util::Polynomial< T >::evaluate ( double  x) const
inline

Evaluate polynomial at specific floating point argument.

Parameters
xvalue of argument x
Returns
Value f(x) of polynomial at specified x

Definition at line 623 of file Polynomial.h.

References Util::Polynomial< T >::degree(), and Util::GArray< T >::size().

template<typename T >
Polynomial< T > Util::Polynomial< T >::monomial ( int  n)
static

Return a monomial f(x) = x^{n}.

Return a monomial.

Parameters
npower of x in monomial.

Definition at line 646 of file Polynomial.h.

References UTIL_CHECK.


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