aboutsummaryrefslogtreecommitdiff
path: root/src/fit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fit.c')
-rw-r--r--src/fit.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/fit.c b/src/fit.c
index 8b17062..66f9a12 100644
--- a/src/fit.c
+++ b/src/fit.c
@@ -127,10 +127,14 @@ int fit_event(event *ev, double *xopt, double *fmin)
do {
*fmin = fval;
+ memcpy(xopt,x,sizeof(x));
rv = nlopt_optimize(opt,x,&fval);
- } while (fabs(fval-*fmin) > 1e-5);
+ } while (fval < *fmin && fabs(fval-*fmin) > 1e-5);
- memcpy(xopt,x,sizeof(x));
+ if (fval < *fmin) {
+ *fmin = fval;
+ memcpy(xopt,x,sizeof(x));
+ }
nlopt_destroy(opt);