42 if (i < 0 || i >=
static_cast<ssize_t
>(
m_knots.
size())) {
55 auto n_less = first_x - xs.
begin();
58 auto o = out.
begin() + n_less;
62 auto x = xs.
begin() + n_less;
85 double integrate(
const double a,
const double b)
const override {
104 auto prevKnotIter = knotIter - 1;
105 if (max <= *prevKnotIter) {
108 if (min < *knotIter) {
109 double down = (min > *prevKnotIter) ? min : *prevKnotIter;
110 double up = (max < *knotIter) ? max : *knotIter;
115 return direction * result;
130 for (
size_t i = 0; i < x.
size() - 1; i++) {
131 coef1[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i]);
132 coef0[i] = y[i] - coef1[i] * x[i];
LinearInterpolator(std::vector< double > knots, std::vector< double > coef0, std::vector< double > coef1)
const std::vector< double > m_coef0
void operator()(const std::vector< double > &xs, std::vector< double > &out) const override
double integrate(const double a, const double b) const override
double antiderivative(int i, double x) const
const std::vector< double > m_coef1
virtual ~LinearInterpolator()=default
double operator()(double x) const override
std::unique_ptr< NAryFunction > clone() const override
Represents a piecewise function.
ssize_t findKnot(double x) const
std::vector< double > m_knots
A vector where the knots are kept.
std::unique_ptr< Function > linearInterpolation(const std::vector< double > &x, const std::vector< double > &y, bool extrapolate)
Performs linear interpolation for the given set of data points.