39 const Polynomial& p1 = dynamic_cast<const Polynomial&>(f1);
40 const Polynomial& p2 = dynamic_cast<const Polynomial&>(f2);
44 for (
size_t i = 0; i < c1.
size(); ++i)
45 for (
size_t j = 0; j < c2.
size(); ++j)
46 resultCoef[i + j] += c1[i] * c2[j];
53 const Piecewise& piecewise = dynamic_cast<const Piecewise&>(f1);
64 auto p1Iter = knots1.
begin();
65 auto p2Iter = knots2.
begin();
67 while (p1Iter != knots1.
end() && p2Iter != knots2.
end()) {
69 if (*p1Iter < *p2Iter) {
70 if (*(++p1Iter) > *p2Iter) {
74 if (*p1Iter < *(++p2Iter)) {
80 if (*p1Iter < *p2Iter) {
81 knotSet.insert(*p1Iter);
84 knotSet.insert(*p2Iter);
93 const Piecewise& p1 = dynamic_cast<const Piecewise&>(f1);
94 const Piecewise& p2 = dynamic_cast<const Piecewise&>(f2);
107 for (
double knot : knots) {
108 if (knot == knots.back()) {
111 while (p1.
getKnots()[i1+1] <= knot) {
114 while (p2.
getKnots()[i2+1] <= knot) {
ELEMENTS_API std::unique_ptr< Function > multiply(const Function &f1, const Function &f2)
std::unique_ptr< Function >(* MultiplyFunction)(const Function &, const Function &)
Alias of a function which multiplies Function objects.
std::unique_ptr< Function > multiplyPolynomials(const Function &f1, const Function &f2)
Function for multiplying two Polynomials. It multiplies their coefficients.
const std::vector< std::shared_ptr< Function > > & getFunctions() const
Returns the functions in the ranges between the knots.
Interface class representing a function.
ELEMENTS_API std::map< std::type_index, MultiplyFunction > multiplySpecificGenericMap
std::unique_ptr< Function > multiplyPiecewiseWithGeneric(const Function &f1, const Function &f2)
Represents a polynomial function.
ELEMENTS_API std::map< std::pair< std::type_index, std::type_index >, MultiplyFunction > multiplySpecificSpecificMap
const std::vector< double > & getCoefficients() const
Returns the coefficients of the polynomial.
const std::vector< double > & getKnots() const
Returns the knots of the piecewise function.
std::unique_ptr< Function > multiplyPiecewises(const Function &f1, const Function &f2)
Represents a piecewise function.
std::vector< double > overlappingKnots(const std::vector< double > &knots1, const std::vector< double > &knots2)
Returns a vector of the overlapping knots from the given vectors.