47 if (i < 0 || i >= static_cast<ssize_t>(
m_knots.
size())) {
61 auto n_less = first_x - xs.
begin();
64 auto o = out.
begin() + n_less;
68 auto x = xs.
begin() + n_less;
97 double integrate(
const double a,
const double b)
const override {
116 auto prevKnotIter = knotIter - 1;
117 if (max <= *prevKnotIter) {
120 if (min < *knotIter) {
121 double down = (min > *prevKnotIter) ? min : *prevKnotIter;
122 double up = (max < *knotIter) ? max : *knotIter;
127 return direction * result;
144 int n = x.
size() - 1;
148 for (
int i = 0; i < n; i++)
149 h[i] = x[i + 1] - x[i];
153 for (
int i = 1; i < n; ++i) {
154 double g = 2. * (x[i + 1] - x[i - 1]) - h[i - 1] * mu[i - 1];
156 z[i] = (3. * (y[i + 1] * h[i - 1] - y[i] * (x[i + 1] - x[i - 1]) + y[i - 1] * h[i]) / (h[i - 1] * h[i]) -
157 h[i - 1] * z[i - 1]) /
170 for (
int j = n - 1; j >= 0; j--) {
172 coef2[j] = z[j] - mu[j] * coef2[j + 1];
173 coef1[j] = (y[j + 1] - y[j]) / h[j] - h[j] * (coef2[j + 1] + 2. * coef2[j]) / 3.;
174 coef3[j] = (coef2[j + 1] - coef2[j]) / (3. * h[j]);
179 for (
int i = 0; i < n; i++) {
181 double x_2 = x_1 * x_1;
182 double x_3 = x_1 * x_2;
183 coef0[i] = coef0[i] + coef1[i] * x_1 + coef2[i] * x_2 + coef3[i] * x_3;
184 coef1[i] = coef1[i] + 2. * coef2[i] * x_1 + 3. * coef3[i] * x_2;
185 coef2[i] = coef2[i] + 3. * coef3[i] * x_1;
CubicInterpolator(std::vector< double > knots, std::vector< double > coef0, std::vector< double > coef1, std::vector< double > coef2, std::vector< double > coef3)
ssize_t findKnot(double x) const
std::unique_ptr< NAryFunction > clone() const override
std::vector< double > m_coef3
std::vector< double > m_coef0
double operator()(double x) const override
std::vector< double > m_coef1
virtual ~CubicInterpolator()=default
std::unique_ptr< Function > splineInterpolation(const std::vector< double > &x, const std::vector< double > &y, bool extrapolate)
Performs cubic spline interpolation for the given set of data points.
std::vector< double > m_coef2
std::vector< double > m_knots
A vector where the knots are kept.
double antiderivative(int i, double x) const
void operator()(const std::vector< double > &xs, std::vector< double > &out) const override
Represents a piecewise function.
double integrate(const double a, const double b) const override