I want to use Brents method as present in the Numerical Recepies Book to minimize a function. The signature of the minimzation routine essentially looks like this:
float brent(float (*f)(float), float *xmin, "other parameters not relevant to question")
As you can guess brent
returns the minimum value of f
and stores its argument in xmin
.
However, the exact form of the function I want to minimize depends on additional parameters. Say
float minimize_me(float x, float a, float b)
Once I decided on the values of a
and b
I want to minimize it with respect to x
.
I could simply add additional arguments to all functions called, all the way down to brent
, thus changing its signature to
float brent(float (*f)(float,float,float),float a ,float b , float *xmin, ...)
and consequently call (*f)(x,a,b)
inside brent
every time. This, however, seems not really elegant to me since I would now have to pass not only the pointer to minimize_me
, but also two additional parameters down a whole chain of functions.
I suspect there could be a more elegant solution, like creating a pointer to a version of the function with a
and b
as fixed values.
Even if it is a really obscure solution, please don't keep it from me, since I feel it could improve my overall understanding of the language.