Simpatico
v1.10
|
A Polynomial (i.e,.
a list of coefficents).
Definition at line 30 of file Polynomial.h.
#include <Polynomial.h>
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 | |
T | 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... | |
|
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.
capacity | initial capacity of coefficient array. |
Definition at line 264 of file Polynomial.h.
References Util::GArray< Data >::reserve().
|
inlineexplicit |
Construct a constant polynomial.
Creates a polynomial f(x) = c, with degree() = 0.
c | constant coefficient value |
Definition at line 272 of file Polynomial.h.
References Util::GArray< Data >::append(), and Util::GArray< Data >::reserve().
|
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.
coeffs | array of coefficients. |
Definition at line 283 of file Polynomial.h.
References Util::GArray< Data >::append(), Util::Array< Data >::capacity(), and Util::GArray< Data >::reserve().
|
inline |
Copy constructor.
other | Polynomial to be copied |
Definition at line 298 of file Polynomial.h.
References Util::GArray< Data >::append(), Util::GArray< T >::capacity(), Util::Polynomial< T >::operator=(), Util::GArray< Data >::reserve(), Util::Polynomial< T >::setToZero(), and Util::GArray< T >::size().
Polynomial<T>& Util::Polynomial< T >::operator= | ( | Polynomial< U > const & | other | ) |
Assignment from another polynomial.
other | Polynomial to assign. |
Referenced by Util::Polynomial< T >::Polynomial().
|
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().
|
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().
Polynomial< T > & Util::Polynomial< T >::operator+= | ( | const Polynomial< T > & | a | ) |
Add another polynomial to this one.
Upon return, *this = this + a.
a | increment (input) |
Definition at line 350 of file Polynomial.h.
References Util::GArray< Data >::append(), Util::GArray< T >::size(), and UTIL_CHECK.
Polynomial< T > & Util::Polynomial< T >::operator+= | ( | T | a | ) |
Add a constant to this polynomial.
Upon return, *this = this + a.
a | increment (input) |
Definition at line 373 of file Polynomial.h.
References Util::GArray< T >::size().
Polynomial< T > & Util::Polynomial< T >::operator-= | ( | const Polynomial< T > & | a | ) |
Subtract another polynomial from this one.
Upon return, *this = this + a.
a | decrement (input) |
Definition at line 387 of file Polynomial.h.
References Util::GArray< Data >::append(), Util::GArray< T >::size(), and UTIL_CHECK.
Polynomial< T > & Util::Polynomial< T >::operator-= | ( | T | a | ) |
Subtract a constant from this polynomial.
Upon return, *this = this + a.
a | increment (input) |
Definition at line 410 of file Polynomial.h.
References Util::GArray< T >::size().
|
inline |
Multiply this polynomial by a scalar.
Upon return, *this = this*a.
a | scalar factor |
Definition at line 425 of file Polynomial.h.
References Util::GArray< T >::size().
|
inline |
Divide this polynomial by a scalar.
Upon return, *this = this*a.
a | scalar factor (input) |
Definition at line 440 of file Polynomial.h.
References Util::GArray< T >::size().
Polynomial< T > & Util::Polynomial< T >::operator*= | ( | const Polynomial< T > & | a | ) |
Multiply this polynomial by another.
Upon return, *this = this*a.
a | increment (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.
Polynomial< T > Util::Polynomial< T >::integrate | ( | ) | const |
Compute and return indefinite integral of this polynomial.
Returns an indefinite integral with zero constant term.
Definition at line 502 of file Polynomial.h.
References Util::DArray< Data >::allocate(), Util::Polynomial< T >::setToZero(), and Util::GArray< T >::size().
Polynomial< T > Util::Polynomial< T >::differentiate | ( | ) | const |
Compute and return derivative of this polynomial.
Returns a polynomial of one smaller degree.
Definition at line 528 of file Polynomial.h.
References Util::DArray< Data >::allocate(), Util::Polynomial< T >::setToZero(), and Util::GArray< T >::size().
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.
Definition at line 557 of file Polynomial.h.
References Util::GArray< T >::size().
Polynomial< T > Util::Polynomial< T >::shift | ( | T | 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.
Definition at line 576 of file Polynomial.h.
References Util::Binomial::coeff(), Util::Polynomial< T >::degree(), Util::Binomial::setup(), and Util::GArray< T >::size().
|
inline |
Evaluate polynomial at specific argument of type T.
x | value of argument |
Definition at line 602 of file Polynomial.h.
References Util::Polynomial< T >::degree(), and Util::GArray< T >::size().
|
inline |
Evaluate polynomial at specific floating point argument.
x | value of argument x |
Definition at line 623 of file Polynomial.h.
References Util::Polynomial< T >::degree(), and Util::GArray< T >::size().
|
static |
Return a monomial f(x) = x^{n}.
Return a monomial.
n | power of x in monomial. |
Definition at line 646 of file Polynomial.h.
References UTIL_CHECK.