I am trying to create a somewhat general single-variable integration routine in c++. I wrote an adaptive quadrature that accepts a pointer to a single variable function, as follows:
typedef complex<double> cd;
cd GaussIntegrate(cd (*f) (cd),cd zmin,cd zmax);
However, I would like to extend it to a general multivariate function. The integration would still be on a single variable, but I would like to allow the function to depend on more than one variable, something like
cd GaussIntegrate(cd (*f) (cd, ...),cd zmin,cd zmax);
so I can use func(cd) or func(cd,double,int) as integration function, for instance.
However, I do not know what would be the best way to create such a template. There should be a way to specify the rest of the parameters, so instead of
GaussIntegrate(&function,zmin,zmax);
I should also be able to write something like
GaussIntegrate(&function(param2,param3),zmin,zmax);
Right now I am doing this through a bridge one-variable function and I specify the rest of the parameters as globals, but that is a very unelegant solution. Anyone could give me a better one?
Thanks,
Jan