![]() |
Vulpes
0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
|
Template class to represent and operate on polynomials. More...
#include <polynomial1d.hpp>
Public Member Functions | |
| Polynomial () | |
| Default constructor. Constructs a polynomial with a zero term. | |
| Polynomial (std::size_t size) | |
| Constructor. Constructs a polynomial with a given size. | |
| Polynomial (const std::vector< T > &coeffs) | |
| Constructs a polynomial with the given coefficients. | |
| auto & | data () |
| const auto & | data () const |
| std::size_t | degree () const |
| Returns the degree of the polynomial. | |
| constexpr std::size_t | size () const |
| Returns the number of the monomials. | |
| const T & | operator[] (std::size_t i) const |
| Accesses the coefficient of the x^i term. | |
| const T & | coef (std::size_t i) const |
| Accesses the coefficient of the x^i term. | |
| T & | coef (std::size_t i) |
| Accesses the coefficient of the x^i term. | |
| Polynomial< T > | derivative () const |
| Computes the derivative of the polynomial. | |
| Polynomial< T > | derivative (std::size_t component) const |
| Computes the derivative of the polynomial. | |
| Eigen::Vector< Polynomial< T >, 1 > | gradient () const |
| Computes the derivative of the polynomial. | |
| void | derivative_ () |
| Computes the derivative of the polynomial in place. | |
| T | integrate (const T &left, const T &right) const |
| Computes the definite integral of the polynomial between two bounds. | |
| Polynomial< T > | primitive (const T &c=T(0)) const |
| Computes the indefinite integral (primitive) of the polynomial. | |
| void | primitive_ (const T &ordinate=T(0), const T &target_value=T(0)) |
| Computes the indefinite integral (primitive) of the polynomial in place. | |
| T | evaluate (const T &x) const |
| Evaluates the polynomial at a given point using Horner's method. | |
| T | evaluate (const Eigen::Vector< T, 1 > &x) const |
| T | evaluate (const T *x) const |
| T | integrate (const Eigen::Map< Eigen::Vector< T, -1 > > &monomial_integrals) const |
| Polynomial< T > | substitute (const Polynomial< T > &poly) const |
| Substitutes another polynomial into the current polynomial. | |
| template<typename U> | |
| Polynomial< U > | to () const |
| Converts the underlying type of the polynomial's coefficients to another type. | |
| Polynomial< T > & | operator+= (const Polynomial< T > &other) |
| Adds another polynomial to the current polynomial in place. | |
| Polynomial< T > & | operator-= (const Polynomial< T > &other) |
| Subtracts another polynomial from the current polynomial in place. | |
| Polynomial< T > & | operator*= (const Polynomial< T > &other) |
| Multiplies the current polynomial by another polynomial in place. | |
| Polynomial< T > & | operator*= (const T &scalar) |
| Multiplies the polynomial by a scalar in place. | |
| Polynomial< T > & | operator/= (const T &scalar) |
| Divides the polynomial by a scalar in place. | |
| Polynomial< T > & | operator%= (const Polynomial< T > &divisor) |
| Computes the remainder of dividing the current polynomial by another polynomial in place. | |
| Polynomial< T > & | operator/= (const Polynomial< T > &divisor) |
| Divides the current polynomial by another polynomial in place. | |
| T | integrate (const datastructure::SimplexDataView< Dim, SimplexData, T, std::size_t > &monomial_integrals) const |
| Integrate the polynomial given the monomials integrals. | |
| Polynomial | primitive (std::size_t component) const |
| Compute the primitive of the polynomial. | |
Static Public Member Functions | |
| static void | divide (const Polynomial< T > &divisor, Polynomial< T > "ient, Polynomial< T > &remainder) |
| Divides one polynomial by another, updating the quotient and remainder. | |
Protected Member Functions | |
| void | trim () |
| Removes leading zeros from the coefficients vector. | |
| Polynomial * | self () |
Protected Attributes | |
| std::vector< T > | m_coefficients |
| Vector storing the coefficients of the polynomial. | |
Friends | |
| Polynomial< T > | operator/ (Polynomial< T > lhs, const Polynomial< T > &rhs) |
| Friend function to compute the remainder of dividing one polynomial by another. | |
| Polynomial< T > | operator% (Polynomial< T > lhs, const Polynomial< T > &rhs) |
| Friend function to compute the remainder of dividing one polynomial by another. | |
| bool | operator== (const Polynomial< T > &lhs, const Polynomial< T > &rhs) |
| Compares two polynomials for equality. | |
| std::ostream & | operator<< (std::ostream &os, const Polynomial< T > &poly) |
| Friend function to output a polynomial to an output stream. | |
Template class to represent and operate on polynomials.
This file contains the implementation of a polynomial class template that supports various operations, including addition, subtraction, multiplication, division, differentiation, integration, and more.
|
inlineexplicit |
Default constructor. Constructs a polynomial with a zero term.
|
inlineexplicit |
Constructor. Constructs a polynomial with a given size.
|
inlineexplicit |
Constructs a polynomial with the given coefficients.
| coeffs | Vector of coefficients, where the i-th element represents the coefficient of the x^i term. |
|
inline |
Accesses the coefficient of the x^i term.
| i | The index of the coefficient to access. |
|
inline |
Accesses the coefficient of the x^i term.
| i | The index of the coefficient to access. |
|
inline |
|
inline |
|
inline |
Returns the degree of the polynomial.
|
inline |
Computes the derivative of the polynomial.
|
inline |
Computes the derivative of the polynomial.
|
inline |
Computes the derivative of the polynomial in place.
This function modifies the current polynomial to be its derivative.
|
inlinestatic |
Divides one polynomial by another, updating the quotient and remainder.
| divisor | The polynomial to divide by. |
| quotient | The quotient polynomial (output). |
| remainder | The remainder polynomial (output). |
|
inline |
|
inline |
Evaluates the polynomial at a given point using Horner's method.
Horner's method is used to efficiently evaluate the polynomial of degree \( n \) at a given point \( x \). The polynomial:
\[P(x) = a_n x^n + a_{n-1} x^{n-1} + \dots + a_1 x + a_0 \]
is rewritten using Horner's rule as:
\[P(x) = (((a_n x + a_{n-1}) x + a_{n-2}) x + \dots + a_1) x + a_0 \]
This reduces the number of multiplications needed to evaluate the polynomial.
| x | The point at which to evaluate the polynomial. |
|
inline |
|
inline |
Computes the derivative of the polynomial.
|
inline |
|
inline |
Computes the definite integral of the polynomial between two bounds.
| left | The lower bound of the integration. |
| right | The upper bound of the integration. |
|
inlineinherited |
Integrate the polynomial given the monomials integrals.
|
inline |
Computes the remainder of dividing the current polynomial by another polynomial in place.
| divisor | The polynomial to divide by. |
|
inline |
Multiplies the current polynomial by another polynomial in place.
| other | The polynomial to multiply with. |
|
inline |
Multiplies the polynomial by a scalar in place.
| scalar | The scalar to multiply with. |
|
inline |
Adds another polynomial to the current polynomial in place.
| other | The polynomial to add. |
|
inline |
Subtracts another polynomial from the current polynomial in place.
| other | The polynomial to subtract. |
|
inline |
Divides the current polynomial by another polynomial in place.
| divisor | The polynomial to divide by. |
|
inline |
Divides the polynomial by a scalar in place.
| scalar | The scalar to divide by. |
|
inline |
Accesses the coefficient of the x^i term.
| i | The index of the coefficient to access. |
|
inline |
Computes the indefinite integral (primitive) of the polynomial.
| c | The constant of integration. |
|
inlineinherited |
Compute the primitive of the polynomial.
|
inline |
Computes the indefinite integral (primitive) of the polynomial in place.
| ordinate | The ordinate (x-value) for which the integral at that point should equal the target_value. |
| target_value | The target value of the integral at the given ordinate. |
|
inlineprotectedinherited |
|
inlineconstexpr |
Returns the number of the monomials.
|
inline |
Substitutes another polynomial into the current polynomial.
| poly | The polynomial to substitute into the current polynomial. |
|
inline |
Converts the underlying type of the polynomial's coefficients to another type.
| U | The target type to which the coefficients should be converted. |
|
inlineprotected |
Removes leading zeros from the coefficients vector.
This function trims the polynomial by removing any leading zeros from the coefficients vector, ensuring the polynomial's degree is correctly represented.
|
friend |
Friend function to compute the remainder of dividing one polynomial by another.
| lhs | The left-hand side polynomial. |
| rhs | The right-hand side polynomial. |
|
friend |
Friend function to compute the remainder of dividing one polynomial by another.
| lhs | The left-hand side polynomial. |
| rhs | The right-hand side polynomial. |
|
friend |
Friend function to output a polynomial to an output stream.
| os | The output stream. |
| poly | The polynomial to output. |
|
friend |
Compares two polynomials for equality.
| lhs | The left-hand side polynomial. |
| rhs | The right-hand side polynomial. |
|
protected |
Vector storing the coefficients of the polynomial.