|
Theoretica
Scientific Computing
|
A polynomial of arbitrary order with coefficients of a specified type. More...
#include <polynomial.h>
Public Member Functions | |
| polynomial ()=default | |
| Default constructor. | |
| polynomial (Type a) | |
| Initialize as a constant. | |
| template<typename Vector , enable_vector< Vector > = true> | |
| polynomial (const Vector &c) | |
| Initialize from a vector of coefficients where the n-th order coefficient is given by the n-th element of the vector. | |
| polynomial (std::initializer_list< Type > l) | |
| Initialize from an std::initializer_list. | |
| template<typename ... Args> | |
| polynomial (Args... args) | |
| Construct a polynomial from its coefficients, where the n-th order coefficient is given by the n-th element of the vector. | |
| const Type & | at (unsigned int i) const |
| Get i-th coefficient by constant reference, with bound checking. | |
| Type & | at (unsigned int i) |
| Access i-th coefficient by reference, with bound checking. | |
| const Type & | operator[] (unsigned int i) const |
| Get the n-th order coefficient by constant reference. | |
| Type & | operator[] (unsigned int i) |
| Get the n-th order coefficient by reference. | |
| template<typename InputType = Type> | |
| Type | eval (InputType x) const |
| Evaluate the polynomial for a given value. | |
| template<typename InputType = Type> | |
| Type | operator() (InputType x) const |
| Evaluate the polynomial for a given value. | |
| unsigned int | degree (real tolerance=MACH_EPSILON) const |
| Find the true order of the polynomial (ignoring trailing null coefficients) | |
| void | trim (real tolerance=MACH_EPSILON) |
| Remove trailing zero coefficients. | |
| const vec< Type > & | coeffs () const |
| Get the coefficients of the polynomial as const reference. | |
| vec< Type > & | coeffs () |
| Get the coefficients of the polynomial as reference. | |
| size_t | size () const |
| Get the number of coefficients. | |
| void | resize (size_t sz) |
| Change the number of coefficients of the polynomial. | |
| polynomial | operator+ (const polynomial &p) const |
| Sum two polynomials. | |
| polynomial | operator- (const polynomial &p) const |
| Subtract a polynomial from another. | |
| polynomial | operator* (const polynomial &p) const |
| Multiply two polynomials. | |
| polynomial | operator/ (const polynomial &d) const |
| Polynomial division. | |
| template<typename ScalarType , disable_vector< ScalarType > = true> | |
| polynomial | operator* (ScalarType a) const |
| Multiply a polynomial by a scalar. | |
| template<typename ScalarType , disable_vector< ScalarType > = true> | |
| polynomial | operator/ (ScalarType a) const |
| Divide a polynomial by a scalar, provided it has coefficients supporting division. | |
| polynomial & | operator+= (const polynomial &p) |
| Sum a polynomial to this one. | |
| polynomial & | operator-= (const polynomial &p) |
| Subtract a polynomial from this one. | |
| polynomial & | operator*= (const polynomial &p) |
| Multiply two polynomials. | |
| template<typename ScalarType , disable_vector< ScalarType > = true> | |
| polynomial & | operator*= (ScalarType a) |
| Multiply a polynomial by a scalar value. | |
| polynomial & | operator/= (const polynomial &a) |
| Divide a polynomial by a polynomial. | |
| template<typename ScalarType , disable_vector< ScalarType > = true> | |
| polynomial & | operator/= (ScalarType a) |
| Divide a polynomial by a scalar value, provided it has coefficients supporting division. | |
| bool | operator== (const polynomial &other) const |
| Check whether two polynomials are equal. | |
| auto | begin () |
| Get an iterator for the first coefficient of the polynomial. | |
| auto | end () |
| Get an iterator for the one plus last coefficient of the polynomial. | |
| auto | cbegin () const |
| Get a const iterator for the first coefficient of the polynomial. | |
| auto | cend () const |
| Get a const iterator for the one plus last coefficient of the polynomial. | |
| vec< complex<>, 2 > | quadratic_roots () const |
| Compute the roots of a quadratic polynomial. | |
| std::string | to_string (const std::string &unknown="x", const std::string &exponentiation="^") const |
| Convert the polynomial to string representation. | |
| operator std::string () | |
| Convert the polynomial to string representation. | |
Static Public Member Functions | |
| template<typename Vector , enable_vector< Vector > = true> | |
| static polynomial< Type > | from_roots (const Vector &roots) |
| Construct a polynomial from its roots Uses numerically stable pairwise multiplication with sorted roots. | |
| static polynomial< Type > | monomial (Type c, unsigned int order) |
| Returns a monomial of the given degree and coefficient. | |
Friends | |
| std::ostream & | operator<< (std::ostream &out, const polynomial &obj) |
| Stream the polynomial in string representation to an output stream (std::ostream) | |
A polynomial of arbitrary order with coefficients of a specified type.
The n-th order coefficient is accessed with p[n] and corresponds to the term \(x^n\).
|
inlineexplicit |
Initialize from a vector of coefficients where the n-th order coefficient is given by the n-th element of the vector.
The constructor may be used explicitly, as polynomial(v).
|
inline |
Evaluate the polynomial for a given value.
Horner's method is used for efficient evaluation.
|
inline |
Evaluate the polynomial for a given value.
Horner's method is used for efficient evaluation.