ALFI
Advanced Library for Function Interpolation
|
Namespace with utility functions for polynomial operations. More...
Functions | |
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer> | |
void | normalize (Container< Number > &p, const Number &epsilon=std::numeric_limits< Number >::epsilon()) |
Normalizes a polynomial by removing leading zero coefficients. | |
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer> | |
Container< Number > | mul (const Container< Number > &p1, const Container< Number > &p2) |
Multiplies two polynomials. | |
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer> | |
std::pair< Container< Number >, Container< Number > > | div (const Container< Number > ÷nd, const Container< Number > &divisor, const Number &epsilon=std::numeric_limits< Number >::epsilon()) |
Divides one polynomial by another. | |
Namespace with utility functions for polynomial operations.
This namespace provides a set of functions for manipulating polynomials, such as normalization, multiplication, and division. All polynomials are represented as containers of coefficients in descending degree order.
void alfi::util::poly::normalize | ( | Container< Number > & | p, |
const Number & | epsilon = std::numeric_limits<Number>::epsilon() ) |
Normalizes a polynomial by removing leading zero coefficients.
Removes leading coefficients that are considered zero within a given tolerance epsilon
. If all coefficients are close to zero, the last one is preserved. If the container is empty, a single zero coefficient is inserted.
p | the polynomial to normalize (a container of coefficients in descending degree order) |
epsilon | the tolerance used to determine whether a coefficient is considered zero (default is machine epsilon) |
Container< Number > alfi::util::poly::mul | ( | const Container< Number > & | p1, |
const Container< Number > & | p2 ) |
Multiplies two polynomials.
Given two polynomials \(p_1\) and \(p_2\) represented as containers of coefficients, this function computes their product using the convolution formula:
\[ (p_1 \cdot p_2)[k] = \sum_{i+j=k}{p_1[i] \cdot p_2[j]} \]
If either polynomial is empty, the function returns an empty container.
p1 | the first polynomial |
p2 | the second polynomial |
p1.size() + p2.size() - 1
) std::pair< Container< Number >, Container< Number > > alfi::util::poly::div | ( | const Container< Number > & | dividend, |
const Container< Number > & | divisor, | ||
const Number & | epsilon = std::numeric_limits<Number>::epsilon() ) |
Divides one polynomial by another.
This function divides the dividend
polynomial \(A\) by the divisor
polynomial \(B\), and returns the quotient
\(Q\) and the remainder
\(R\) such that:
\[ A(x) = B(X) \cdot Q(x) + R(x) \]
with either \(R\) being effectively zero or the degree of \(R\) being lower than the degree of \(B\).
The division is performed using a tolerance epsilon
to determine when a coefficient is considered zero.
If the divisor is effectively zero or if the dividend has a lower degree than the divisor, the function returns an empty quotient and the dividend as the remainder.
dividend | the polynomial to be divided |
divisor | the polynomial to divide by |
epsilon | the tolerance used to determine whether a coefficient is considered zero (default is machine epsilon) |
{quotient, remainder}