21 #ifndef OPM_LINEARINTERPOLATION_HEADER_INCLUDED
22 #define OPM_LINEARINTERPOLATION_HEADER_INCLUDED
31 inline int tableIndex(
const std::vector<double>& table,
double x)
36 int n = table.size() - 1;
42 bool ascend = (table[n] > table[0]);
45 if ( (x >= table[jm]) == ascend) {
55 inline double linearInterpolationDerivative(
const std::vector<double>& xv,
56 const std::vector<double>& yv,
double x)
59 int ix1 = tableIndex(xv, x);
61 return (yv[ix2] - yv[ix1])/(xv[ix2] - xv[ix1]);
64 inline double linearInterpolation(
const std::vector<double>& xv,
65 const std::vector<double>& yv,
double x)
68 int ix1 = tableIndex(xv, x);
70 return (yv[ix2] - yv[ix1])/(xv[ix2] - xv[ix1])*(x - xv[ix1]) + yv[ix1];
73 inline double linearInterpolationNoExtrapolation(
const std::vector<double>& xv,
74 const std::vector<double>& yv,
double x)
84 int ix1 = tableIndex(xv, x);
86 return (yv[ix2] - yv[ix1])/(xv[ix2] - xv[ix1])*(x - xv[ix1]) + yv[ix1];
89 inline double linearInterpolation(
const std::vector<double>& xv,
90 const std::vector<double>& yv,
94 ix1 = tableIndex(xv, x);
96 return (yv[ix2] - yv[ix1])/(xv[ix2] - xv[ix1])*(x - xv[ix1]) + yv[ix1];
107 #endif // OPM_LINEARINTERPOLATION_HEADER_INCLUDED