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