|
|
A class for representing univariate polynomials of the form cdxd + cd-1xd-1 + ... + c1x + c0.
Representation:
Polynomial ()
| Polynomial |
no-agrument constructor
Post: c = _
Polynomial (int d = 0, double *coefs = NULL)
| Polynomial |
Constructor.
Pre: d
>= 0
Post: d
= 0 -> c = _ /\
d
!= 0 -> c = coefficients from coefs
Parameters:
d | the degree of the polynomial |
coefs | pointer to an array containing the
coefficients in ascending order
(i.e., coefs[0] is c_0). Note
that the number of coefficients should be
one more than the degree.
|
double operator() (double x)
| operator() |
[const]
evaluate the polynomial at x
Pre: this.degree() >= 0 (i.e., the polynomial is defined)
Parameters:
x | value to evalute the polynomial at |
Returns: the value of this polynomial evaluated at x
int degree ()
| degree |
[const]
degree of the polynomial
Returns: the degree (i.e., exponent of highest order coefficient) of this polynomial or -1 if the polynomial is undefined
Polynomial& operator += (const Polynomial& r)
| operator += |
add a polynomial to this
Post: c' = [c0 + r0, c1 + r1 ... ] /\ Result = *this
Returns: this + r
Polynomial& operator *= (const Polynomial& r)
| operator *= |
multiply a polynomial by this
Post: c' = coefficients for product (this * r) /\ Result = *this
Returns: this * r