26 template <
typename number>
29 const unsigned int n_intervals,
30 const unsigned int interval,
31 const bool spans_next_interval)
32 : polynomial(coefficients_on_interval)
33 , n_intervals(n_intervals)
35 , spans_two_intervals(spans_next_interval)
43 template <
typename number>
46 std::vector<number> &values)
const
50 value(x, values.size() - 1, values.data());
55 template <
typename number>
58 const unsigned int n_derivatives,
59 number * values)
const
63 double derivative_change_sign = 1.;
66 const number step = 1. / n_intervals;
68 if (spans_two_intervals)
70 const double offset = step * interval;
71 if (x < offset || x > offset + step + step)
73 for (
unsigned int k = 0; k <= n_derivatives; ++k)
77 else if (x < offset + step)
81 derivative_change_sign = -1.;
82 y = offset + step + step - x;
87 const double offset = step * interval;
88 if (x < offset || x > offset + step)
90 for (
unsigned int k = 0; k <= n_derivatives; ++k)
100 if ((std::abs(y) < 1
e-14 &&
101 (interval > 0 || derivative_change_sign == -1.)) ||
102 (std::abs(y - step) < 1
e-14 &&
103 (interval < n_intervals - 1 || derivative_change_sign == -1.)))
105 values[0] =
value(x);
106 for (
unsigned int d = 1;
d <= n_derivatives; ++
d)
112 polynomial.value(y, n_derivatives, values);
115 for (
unsigned int j = 1; j <= n_derivatives; j += 2)
116 values[j] *= derivative_change_sign;
121 template <
typename number>
125 return (polynomial.memory_consumption() +
133 std::vector<PiecewisePolynomial<double>>
135 const unsigned int n_subdivisions,
136 const unsigned int base_degree)
138 std::vector<Polynomial<double>> p_base =
139 LagrangeEquidistant::generate_complete_basis(base_degree);
140 for (
auto &polynomial : p_base)
141 polynomial.scale(n_subdivisions);
143 std::vector<PiecewisePolynomial<double>> p;
144 p.reserve(n_subdivisions * base_degree + 1);
146 p.emplace_back(p_base[0], n_subdivisions, 0,
false);
147 for (
unsigned int s = 0; s < n_subdivisions; ++s)
148 for (
unsigned int i = 0; i < base_degree; ++i)
149 p.emplace_back(p_base[i + 1],
152 i == (base_degree - 1) && s < n_subdivisions - 1);
162 template class PiecewisePolynomial<float>;
163 template class PiecewisePolynomial<double>;
164 template class PiecewisePolynomial<long double>;