diff --git a/ex-1/tests.c b/ex-1/tests.c index 91b86d1..52352cc 100644 --- a/ex-1/tests.c +++ b/ex-1/tests.c @@ -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