I want to do a numerical integration of a function f using the qtrap function defined in "Numerical recipes in C".
double qtrap(double (*func)(double), double a, double b);
As shown, it is a 1-d integration of a variable of type double.
But the function I want to integrate has an additional parameter a:
double f(double x, int a)
{
return a + x * x;
}
Now I am looking for a way to integrate f for different values of a.
My idea up to now:
typedef double (*fctp1_t)(double); //function pointer type for 1 arg
typedef double (*fctp2_t)(double, int); //function pointer type for 2 args
int a = 10;
fctp1_t = f1d;
f1d = reduceArgument(f, a);
qtrap(f1d, 0, 1);
with the reduceArgument something like this:
fctp1_t reduceArgument(fctp2_t f2d, int ia)
{
return f2d(x, ia);
}
This code results in the error: 'x' undeclared.
Thanks for any suggestions.