J
jack
Hi all,
Suppose I have a routine to find the maximum
of any *univariate* function f in the interval [a, b]:
double f(double x);
double findmax(double (*func)(double), double a, double b);
Now I have a function with three variables:
double g(double x, double y, double z);
And I want to find the maximum of g, with y=y0 and z=z0 fixed, and
x in the interval [a, b].
How can I achieve this? Since C++ does not allow local functions,
the only thing I can think of right now is to modify the findmax
function:
double findmax(double (*func)(double, double, double),
double y, double z, double a, double b);
However, this means if someday I have another function h with four variables,
I'll have to modify findmax again. How can I have a universal findmax?
Thanks for your help.
jack
Suppose I have a routine to find the maximum
of any *univariate* function f in the interval [a, b]:
double f(double x);
double findmax(double (*func)(double), double a, double b);
Now I have a function with three variables:
double g(double x, double y, double z);
And I want to find the maximum of g, with y=y0 and z=z0 fixed, and
x in the interval [a, b].
How can I achieve this? Since C++ does not allow local functions,
the only thing I can think of right now is to modify the findmax
function:
double findmax(double (*func)(double, double, double),
double y, double z, double a, double b);
However, this means if someday I have another function h with four variables,
I'll have to modify findmax again. How can I have a universal findmax?
Thanks for your help.
jack