M
Martin Bootsma
I have a C question, which looks very easy, but no one here seems to
know an easy answer.
I have a function "powell" (from Numerical Recipes) which takes an
argument of the type
"double (*f)(float[])"
But I want to be able to pass a
"double (*f)(float[], double)"
instead, where minimization is with respect to the the first argument
and
the second argument is a parameter.
Below is a very easy version of the problem.
// Problem: Minimize function with additional parameters
// function you want to minimize, example below is trivial
// and 1 dimensional
double g(float x[],double a)
{ return (x[1]+a)*(x[1]+a); }
// so minimization should result in x[1]=-a.
int main (void)
{
//define other parameters required for the function powell
int n=1;
float *p,**xi;
p=vector(1,n);
p[1]=0.2;
xi=matrix(1,n,1,n);
xi[1][1]=1;
float ftol=0.000001;
int iter=0;
float fret;
double a=(double) rand();
//How to pass the parameter a into the minimization function powell.
//While the parameter a is defined during the running time.
//i.e., one likes to enter g(.,a) in te function
powell(p,xi,n,ftol,&iter,&fret, );
//where the last argument should be a function of the required form
}
Any help is appreciated.
Martin
know an easy answer.
I have a function "powell" (from Numerical Recipes) which takes an
argument of the type
"double (*f)(float[])"
But I want to be able to pass a
"double (*f)(float[], double)"
instead, where minimization is with respect to the the first argument
and
the second argument is a parameter.
Below is a very easy version of the problem.
// Problem: Minimize function with additional parameters
// function you want to minimize, example below is trivial
// and 1 dimensional
double g(float x[],double a)
{ return (x[1]+a)*(x[1]+a); }
// so minimization should result in x[1]=-a.
int main (void)
{
//define other parameters required for the function powell
int n=1;
float *p,**xi;
p=vector(1,n);
p[1]=0.2;
xi=matrix(1,n,1,n);
xi[1][1]=1;
float ftol=0.000001;
int iter=0;
float fret;
double a=(double) rand();
//How to pass the parameter a into the minimization function powell.
//While the parameter a is defined during the running time.
//i.e., one likes to enter g(.,a) in te function
powell(p,xi,n,ftol,&iter,&fret, );
//where the last argument should be a function of the required form
}
Any help is appreciated.
Martin