H
Hicham Mouline
hi,
I have a map<double,double> of data points (xi,yi), modelling a function to
interpolate.
Assuming the points are monotone increasing, such that, i>j, yi> yj if xi>xj
How do i get the inverse of a point y inside the range of yi?
typedef std::map<double, double>::const_iterator CCI;
CCI endi = f.end();
for (CCI iter=f.begin(); iter!=endi; ++iter)
if (iter->second > x)
break;
if (iter==endi)
return NaN;
CCI prev = iter;
--prev;
if (iter->second = prev->second) // shouldn't happen
return prev->first;
return prev->first + (x - prev->second)*(iter->first -
prev->first)/(iter->second - prev->second);
Comments re correctness and performance (if this were to be called inside a
tight loop) are appreciated,
rds,
I have a map<double,double> of data points (xi,yi), modelling a function to
interpolate.
Assuming the points are monotone increasing, such that, i>j, yi> yj if xi>xj
How do i get the inverse of a point y inside the range of yi?
typedef std::map<double, double>::const_iterator CCI;
CCI endi = f.end();
for (CCI iter=f.begin(); iter!=endi; ++iter)
if (iter->second > x)
break;
if (iter==endi)
return NaN;
CCI prev = iter;
--prev;
if (iter->second = prev->second) // shouldn't happen
return prev->first;
return prev->first + (x - prev->second)*(iter->first -
prev->first)/(iter->second - prev->second);
Comments re correctness and performance (if this were to be called inside a
tight loop) are appreciated,
rds,