34 std::unique_ptr<Function>
linearInterpolation(
const std::vector<double>& x,
const std::vector<double>& y,
36 std::vector<std::shared_ptr<Function>> functions {};
37 for (
size_t i=0; i<x.size()-1; i++) {
38 double coef1 = (y[i+1]-y[i]) / (x[i+1]-x[i]);
39 double coef0 = y[i] - coef1*x[i];
40 functions.push_back(std::shared_ptr<Function>(
new Polynomial{{coef0,coef1}}));
44 std::vector<double> x_copy(x);
45 x_copy.front() = std::numeric_limits<double>::lowest();
46 x_copy.back() = std::numeric_limits<double>::max();
47 return std::unique_ptr<Function>(
new Piecewise{x_copy, std::move(functions)});
50 return std::unique_ptr<Function>(
new Piecewise{x, std::move(functions)});
Represents a polynomial function.
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.
Represents a piecewise function.