17 #ifndef SPLINEFUNCTION_H
18 #define SPLINEFUNCTION_H
25 std::vector<std::pair<double, double>>
vals;
28 for (
unsigned int i = 0;
i <
x.size(); ++
i) {
29 vals.push_back(std::make_pair(
x[
i],
y[
i]));
34 vals.push_back(std::make_pair(
x, val));
37 double f(
double arg)
const {
38 if (
vals.size() < 2)
return 0.;
40 std::pair<double, double> op = std::make_pair(arg, 0.);
41 std::vector<std::pair<double, double>>::const_iterator it =
42 lower_bound(
vals.begin(),
vals.end(), op);
43 ind = distance(
vals.begin(), it);
46 + (arg -
vals[0].first) * (
vals[1].second -
vals[0].second)
48 if (ind ==
vals.size())
49 return vals[ind - 2].second
51 * (
vals[ind - 1].second -
vals[ind - 2].second)
53 return vals[ind - 1].second
54 + (arg -
vals[ind - 1].first)
55 * (
vals[ind].second -
vals[ind - 1].second)
56 / (
vals[ind].first -
vals[ind - 1].first);
70 void fill(std::vector<double>
x, std::vector<double>
y) {
72 for (
unsigned int i = 0;
i <
x.size(); ++
i) {
73 vals.push_back(std::make_pair(
x[
i],
y[
i]));
79 vals.push_back(std::make_pair(0., val));
80 vals.push_back(std::make_pair(1., val));
85 #endif // SPLINEFUNCTION_H