ex-1: changed do-while with for

This commit is contained in:
Giù Marcer 2020-04-27 23:22:24 +02:00 committed by rnhmjoj
parent 894854948d
commit c560f3c57c

View File

@ -93,7 +93,6 @@ double numeric_mode(double min, double max,
// initialize minimization
double x = 0;
int iter = 0;
int max_iter = 100;
double prec = 1e-7;
int status;
@ -102,15 +101,14 @@ double numeric_mode(double min, double max,
gsl_min_fminimizer_set(s, &npdf, x, min, max);
// minimisation
do {
iter++;
status = gsl_min_fminimizer_iterate(s);
x = gsl_min_fminimizer_x_minimum(s);
min = gsl_min_fminimizer_x_lower(s);
max = gsl_min_fminimizer_x_upper(s);
status = gsl_min_test_interval(min, max, 0, prec);
} while (status == GSL_CONTINUE && iter < max_iter);
for (int iter = 0; status == GSL_CONTINUE && iter < max_iter; iter++)
{
status = gsl_min_fminimizer_iterate(s);
x = gsl_min_fminimizer_x_minimum(s);
min = gsl_min_fminimizer_x_lower(s);
max = gsl_min_fminimizer_x_upper(s);
status = gsl_min_test_interval(min, max, 0, prec);
}
/* The error is simply given by the width of
* the final interval containing the solution