23#ifndef VULPES_POLYNOMIALS_POLYNOMIAL1D_HPP_
24#define VULPES_POLYNOMIALS_POLYNOMIAL1D_HPP_
126 assert(component == 0);
137 return Eigen::Vector<Polynomial<T>, 1>{
derivative()};
165 return primitive_inst.evaluate(right) - primitive_inst.evaluate(left);
192 void primitive_(
const T& ordinate = T(0),
const T& target_value = T(0)) {
194 !std::is_integral_v<T>,
195 "Primitive is not well defined for integral polynomial types");
200 const auto ordinate_value = ordinate == T(0) ? T(0) :
evaluate(ordinate);
238 const Eigen::Map<Eigen::Vector<T, -1>>& monomial_integrals)
const {
272 template <
typename U>
274 std::vector<U> new_coefficients;
326 std::vector<T> result(
364 !std::is_integral_v<T>,
365 "Division is not well defined for integral polynomial types");
388 !std::is_integral_v<T>,
389 "Division is not well defined for integral polynomial types");
394 const std::size_t degree_diff = remainder.
degree() - divisor.
degree();
398 std::vector<T> term(degree_diff + 1, T(0));
399 term.back() = leading_coeff;
402 quotient += term_poly;
403 remainder -= (term_poly * divisor);
483 for (std::size_t j = 0; j <= poly.
degree(); ++j) {
484 const auto i = poly.
degree() - j;
485 if (poly[i] != T(0)) {
493 if (i == 0 || poly[i] != T(1)) {
549 std::vector<Polynomial<T>> legendre_polynomials;
551 legendre_polynomials.push_back(one);
553 return legendre_polynomials;
558 for (std::size_t n = 1; n < deg + 1; n++) {
559 const auto& Pn_1 = legendre_polynomials[n - 1];
560 const auto& Pn = legendre_polynomials[n];
563 legendre_polynomials.push_back(coef1 * X * Pn - coef2 * Pn_1);
564 legendre_polynomials.back() /= T(n + 1);
566 return legendre_polynomials;
Base template class for a general polynomial.
Definition polynomial.hpp:46
Template class to represent and operate on polynomials.
Definition polynomial1d.hpp:44
friend Polynomial< T > operator%(Polynomial< T > lhs, const Polynomial< T > &rhs)
Friend function to compute the remainder of dividing one polynomial by another.
Definition polynomial1d.hpp:459
Polynomial< T > & operator-=(const Polynomial< T > &other)
Subtracts another polynomial from the current polynomial in place.
Definition polynomial1d.hpp:306
friend Polynomial< T > operator/(Polynomial< T > lhs, const Polynomial< T > &rhs)
Friend function to compute the remainder of dividing one polynomial by another.
Definition polynomial1d.hpp:445
T evaluate(const T *x) const
Definition polynomial1d.hpp:235
T evaluate(const T &x) const
Evaluates the polynomial at a given point using Horner's method.
Definition polynomial1d.hpp:222
Polynomial< T > & operator*=(const T &scalar)
Multiplies the polynomial by a scalar in place.
Definition polynomial1d.hpp:346
Polynomial< U > to() const
Converts the underlying type of the polynomial's coefficients to another type.
Definition polynomial1d.hpp:273
Eigen::Vector< Polynomial< T >, 1 > gradient() const
Computes the derivative of the polynomial.
Definition polynomial1d.hpp:136
Polynomial< T > & operator+=(const Polynomial< T > &other)
Adds another polynomial to the current polynomial in place.
Definition polynomial1d.hpp:287
Polynomial(const std::vector< T > &coeffs)
Constructs a polynomial with the given coefficients.
Definition polynomial1d.hpp:62
Polynomial< T > primitive(const T &c=T(0)) const
Computes the indefinite integral (primitive) of the polynomial.
Definition polynomial1d.hpp:175
T evaluate(const Eigen::Vector< T, 1 > &x) const
Definition polynomial1d.hpp:234
Polynomial< T > substitute(const Polynomial< T > &poly) const
Substitutes another polynomial into the current polynomial.
Definition polynomial1d.hpp:253
void trim()
Removes leading zeros from the coefficients vector.
Definition polynomial1d.hpp:520
T & coef(std::size_t i)
Accesses the coefficient of the x^i term.
Definition polynomial1d.hpp:105
friend bool operator==(const Polynomial< T > &lhs, const Polynomial< T > &rhs)
Compares two polynomials for equality.
Definition polynomial1d.hpp:471
void primitive_(const T &ordinate=T(0), const T &target_value=T(0))
Computes the indefinite integral (primitive) of the polynomial in place.
Definition polynomial1d.hpp:192
auto & data()
Definition polynomial1d.hpp:66
Polynomial< T > derivative(std::size_t component) const
Computes the derivative of the polynomial.
Definition polynomial1d.hpp:125
constexpr std::size_t size() const
Returns the number of the monomials.
Definition polynomial1d.hpp:81
friend std::ostream & operator<<(std::ostream &os, const Polynomial< T > &poly)
Friend function to output a polynomial to an output stream.
Definition polynomial1d.hpp:482
void derivative_()
Computes the derivative of the polynomial in place.
Definition polynomial1d.hpp:145
const T & coef(std::size_t i) const
Accesses the coefficient of the x^i term.
Definition polynomial1d.hpp:97
const T & operator[](std::size_t i) const
Accesses the coefficient of the x^i term.
Definition polynomial1d.hpp:89
std::vector< T > m_coefficients
Vector storing the coefficients of the polynomial.
Definition polynomial1d.hpp:511
static void divide(const Polynomial< T > &divisor, Polynomial< T > "ient, Polynomial< T > &remainder)
Divides one polynomial by another, updating the quotient and remainder.
Definition polynomial1d.hpp:383
Polynomial< T > & operator/=(const T &scalar)
Divides the polynomial by a scalar in place.
Definition polynomial1d.hpp:362
Polynomial< T > derivative() const
Computes the derivative of the polynomial.
Definition polynomial1d.hpp:113
Polynomial(std::size_t size)
Constructor. Constructs a polynomial with a given size.
Definition polynomial1d.hpp:54
Polynomial< T > & operator/=(const Polynomial< T > &divisor)
Divides the current polynomial by another polynomial in place.
Definition polynomial1d.hpp:428
T integrate(const T &left, const T &right) const
Computes the definite integral of the polynomial between two bounds.
Definition polynomial1d.hpp:163
Polynomial()
Default constructor. Constructs a polynomial with a zero term.
Definition polynomial1d.hpp:49
T integrate(const Eigen::Map< Eigen::Vector< T, -1 > > &monomial_integrals) const
Definition polynomial1d.hpp:237
std::size_t degree() const
Returns the degree of the polynomial.
Definition polynomial1d.hpp:74
Polynomial< T > & operator*=(const Polynomial< T > &other)
Multiplies the current polynomial by another polynomial in place.
Definition polynomial1d.hpp:325
Polynomial< T > & operator%=(const Polynomial< T > &divisor)
Computes the remainder of dividing the current polynomial by another polynomial in place.
Definition polynomial1d.hpp:416
const auto & data() const
Definition polynomial1d.hpp:67
Definition monomial.hpp:39
std::vector< Polynomial< T > > buildLegendrePolynomials(std::size_t deg)
Builds a set of Legendre polynomials up to a given degree.
Definition polynomial1d.hpp:548
V to(const U &src)
Converts a value of one pseudo-arithmetic type to another.
Definition vmath.hpp:321
Definition cell_manager.hpp:38