26 std::vector<double> supporting_points,
29 bool supp_pnts_sorted)
30 : supp_pnts_(std::move(supporting_points)),
31 values_at_supp_pnts_(std::move(values_at_supp_pnts))
33 if (!supp_pnts_sorted)
43 const std::size_t i = std::distance(
supp_pnts_.begin(), it);
45 "Variable {:d} and variable {:d} are the same. Piecewise linear "
46 "interpolation is not possible\n",
66 std::size_t
const interval_idx = std::distance(
supp_pnts_.begin(), it) - 1;
70 double const x_r =
supp_pnts_[interval_idx + 1];
77 const double m = (f_r - f) / (x_r - x);
79 return m * (pnt_to_interpolate - x) + f;
83 double const pnt_to_interpolate)
const
93 std::size_t interval_idx = std::distance(
supp_pnts_.begin(), it);
100 if (interval_idx > 1 && interval_idx <
supp_pnts_.size() - 2)
103 double const x_ll =
supp_pnts_[interval_idx - 2];
104 double const x_l =
supp_pnts_[interval_idx - 1];
106 double const x_r =
supp_pnts_[interval_idx + 1];
114 double const tangent_right = (f_l - f_r) / (x_l - x_r);
115 double const tangent_left = (f_ll - f) / (x_ll - x);
116 double const w = (pnt_to_interpolate - x) / (x_l - x);
117 return (1. - w) * tangent_right + w * tangent_left;
Definition of the PiecewiseLinearInterpolation class.
std::vector< double > supp_pnts_
std::vector< double > values_at_supp_pnts_
double getSupportMin() const
PiecewiseLinearInterpolation(std::vector< double > supporting_points, std::vector< double > values_at_supp_pnts, bool supp_pnts_sorted=false)
double getDerivative(double const pnt_to_interpolate) const
Calculates derivative using quadratic interpolation and central difference quotient.
double getSupportMax() const
double getValue(double pnt_to_interpolate) const
Calculates the interpolation value.
void quicksort(It1 first1, It1 last1, It2 first2, Comparator compare)
Definition of the quicksort function.