From c560f3c57c1019727a0e98381b96b91313ef7664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gi=C3=B9=20Marcer?= Date: Mon, 27 Apr 2020 23:22:24 +0200 Subject: [PATCH] ex-1: changed do-while with for --- ex-1/tests.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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