help-gsl
[Top][All Lists]

## [Help-gsl] gsl_min_fminimizer_f_minimum

 From: David Doria Subject: [Help-gsl] gsl_min_fminimizer_f_minimum Date: Mon, 19 May 2008 14:17:15 -0400

```I am trying to minimize a distance function.  The problem is, the function
Distance is squared distance, so it should always be positive.  I output the
value that Distance returns and it is indeed positive.  However when i
output gsl_min_fminimizer_f_minimum(s) at every iteration it is negative!!??
My code is below - am I doing something wrong?

double MinimizeDistance(MyParam_T &MyParams)
{
size_t iter = 0;
int MAX_ITER = 20;

int status;
const gsl_min_fminimizer_type *T;
gsl_min_fminimizer *s;

double a = -10;
double b = 10;
double m = 2;
double val;

gsl_function F;
F.function = &Distance; //my function is double Distance(double T, void
*params)
F.params = &MyParams;

T = gsl_min_fminimizer_goldensection;

s = gsl_min_fminimizer_alloc(T);
gsl_min_fminimizer_set(s, &F, m, a, b);

do
{
iter++;
status = gsl_min_fminimizer_iterate(s);
a = gsl_min_fminimizer_x_lower(s);
b = gsl_min_fminimizer_x_upper(s);
m = gsl_min_fminimizer_x_minimum(s);
val = gsl_min_fminimizer_f_minimum(s);

status = gsl_min_test_interval(a, b, .1, 0);

if(verbosity >= 2)
printf("Iter: [%u %u] Min: %f Val: %f\n", a, b, m, val);
}
while ( (status == GSL_CONTINUE) && (iter < MAX_ITER) );

double fmin = gsl_min_fminimizer_f_minimum(s);

gsl_min_fminimizer_free(s);

return fmin;

}

--
Thanks,

David

```