PSCF v1.1
List of all members
Util::Polynomial< T > Class Template Reference

A Polynomial (i.e,. More...

#include <Polynomial.h>

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

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+= (Polynomial< T > const &a)
 Add another polynomial to this one. More...
 
Polynomial< T > & operator+= (T a)
 Add a constant to this polynomial. More...
 
Polynomial< T > & operator-= (Polynomial< T > const &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*= (Polynomial< T > const &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 Polynomial< T > monomial (int n)
 Return a monomial f(x) = x^{n}. More...
 

Detailed Description

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

A Polynomial (i.e,.

a list of coefficents).

Definition at line 29 of file Polynomial.h.

Constructor & Destructor Documentation

◆ Polynomial() [1/4]

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 263 of file Polynomial.h.

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

◆ Polynomial() [2/4]

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 271 of file Polynomial.h.

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

◆ Polynomial() [3/4]

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 282 of file Polynomial.h.

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

◆ Polynomial() [4/4]

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

Copy constructor.

Parameters
otherPolynomial to be copied

Definition at line 297 of file Polynomial.h.

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

Member Function Documentation

◆ operator=()

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

Assignment from another polynomial.

Parameters
otherPolynomial to assign.

Definition at line 313 of file Polynomial.h.

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

◆ setToZero()

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 334 of file Polynomial.h.

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

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

◆ degree()

template<typename T >
int Util::Polynomial< T >::degree
inline

Return degree of polynomial.

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

Definition at line 342 of file Polynomial.h.

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

◆ operator+=() [1/2]

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

Add another polynomial to this one.

Upon return, *this = this + a.

Parameters
aincrement (input)

Definition at line 349 of file Polynomial.h.

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

◆ operator+=() [2/2]

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 372 of file Polynomial.h.

◆ operator-=() [1/2]

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

Subtract another polynomial from this one.

Upon return, *this = this + a.

Parameters
adecrement (input)

Definition at line 386 of file Polynomial.h.

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

◆ operator-=() [2/2]

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 409 of file Polynomial.h.

◆ operator*=() [1/2]

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 424 of file Polynomial.h.

◆ operator/=()

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 439 of file Polynomial.h.

◆ operator*=() [2/2]

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

Multiply this polynomial by another.

Upon return, *this = this*a.

Parameters
aincrement (input)

Definition at line 453 of file Polynomial.h.

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

◆ integrate()

template<typename T >
Polynomial< T > Util::Polynomial< T >::integrate

Compute and return indefinite integral of this polynomial.

Returns an indefinite integral with zero constant term.

Returns
indefinite integral polynomial.

Definition at line 501 of file Polynomial.h.

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

◆ differentiate()

template<typename T >
Polynomial< T > Util::Polynomial< T >::differentiate

Compute and return derivative of this polynomial.

Returns a polynomial of one smaller degree.

Returns
derivative polynomial

Definition at line 527 of file Polynomial.h.

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

◆ reflect()

template<typename T >
Polynomial< T > Util::Polynomial< T >::reflect

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 556 of file Polynomial.h.

◆ shift()

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 575 of file Polynomial.h.

References Util::Binomial::coeff(), and Util::Binomial::setup().

◆ operator()()

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 601 of file Polynomial.h.

◆ evaluate()

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 622 of file Polynomial.h.

◆ monomial()

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 645 of file Polynomial.h.

References UTIL_CHECK.


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