00001 #include "finterpolate.h" 00002 00003 FInterpolate::FInterpolate(Function1D &f, double a, double b, unsigned N):_f(f) 00004 { 00005 _a=a; 00006 _b=b; 00007 assert(_a < _b); 00008 _N=N; 00009 _dx=(_b-_a)/_N; 00010 00011 _fVals.reinit(_N+1); 00012 for (int i=0; i<=_N; i++) _fVals(i)=_f(_a+i*_dx); 00013 } 00014 00015 double FInterpolate::operator()(double x,unsigned cmp=0) const 00016 { 00017 assert(isInDomain(x,cmp)); 00018 unsigned index = floor((x-_a)/_dx); 00019 if (index == _N) return _fVals(_N); 00020 return ((_fVals(index+1)-_fVals(index))/_dx )*(x-(_a+(index)*_dx)) + _fVals(index); 00021 } 00022 00023 bool FInterpolate::isInDomain(double x,unsigned cmp=0) const 00024 { 00025 if (_a <= x && x <= _b) return 1; 00026 return 0; 00027 } 00028 00029 FInterpolate::~FInterpolate(){}