Integrate an interpolated function

Hi,

I would like to integrate an interpolated function with a arithmetic function, say for example an Exponential function.

The interpolation class allows integration but only on it’s own.

The integrator class works with a IGenfunction (or a C++ callable object implementing operator()(double x) ).

One obvious solution would be to use the operator() member function of the interpolation class, but such member function is private.

Is it possible to create an IGenfuntion from an interpolated object, so that it can be used with the integrator class?

Hi,

I am not sure I have fully understood you. If you need to integrate the interpolation function directly you can use the function Interpolator::Integ(a,b).

If you need to create another function object using the interpolation one you can do as following (the new functionis the interpolation multiplied by an exponential)

struct MyNewFunc { 
  MyNewFunc( ROOT::Math::Interpolator * it) : fInterp(it) {}
  double operator() (double x) { 
     return fInterp->Eval(x) * std::exp(x); 
  }
  ROOT::Math::Interpolator * fInterp; 
};

Then you can use directly this new function object in the integrator class.

Best Regards

Lorenzo

Hi Lorenzo,

Defined a new class using your sugestion (code) and, after applying a wrappedfunction, I was able to integrate the interpolated data with any arithmetic function.

Thank very much you for your help.

Kind regards,

Miguel