Using a functor with qtrap


MPD78
06-04-2012, 05:48 PM
Hello all,

I have a simple linear function that I want to integrate using a functor.

Two values are passed to the functor that make up the simple linear equation that I want to use qtrap to integrate.

struct SCalc{
Doub Const1, Const2;
SCalc(const Doub cconst1, const Doub cconst2) : Const1(cconst2), Const2(cconst2) {}
Doub operator()(const Doub x) {
return Const1 - Const2*x;
}
};

Const1 and Const2 are the two values that make up the simple linear equation that needs to be integrated with respect to x.

a and b are the limits of integration.

Here is the function that calls the functor.

double Sh(const Doub &a, const Doub &b, const Doub &Const1, const Doub &Const2)
{
SCalc f(Const1,Const2);
Doub result;
result = qtrap(f, a, b);
return result;
}

However, the integral is not returned. The difference between Const1 and Const2 is returned. So, I know the error must be in the struct used to create the linear function.

How can I correct the struct to obtain the correct result from qtrap?

Thanks
M.