--- nlopt-2.3/bobyqa/bobyqa.c	2012-07-20 20:13:42.000000000 +0200
+++ nlopt-2.3.1/bobyqa/bobyqa.c	2013-07-25 09:49:26.000000000 +0200
@@ -3086,7 +3086,7 @@
     double temp, zero;
     int ibmat, izmat;
 
-    double rhobeg, rhoend;
+    double rhobeg, rhoend, t;
     double *w0 = NULL, *w;
     nlopt_result ret;
     double *s = NULL, *sxl = NULL, *sxu = NULL, *xs = NULL;
@@ -3104,12 +3104,21 @@
 
     sxl = nlopt_new_rescaled(U(n), s, xl);
     if (!sxl) { ret = NLOPT_OUT_OF_MEMORY; goto done; }
-    xl = sxl;
+
     sxu = nlopt_new_rescaled(U(n), s, xu);
     if (!sxu) { ret = NLOPT_OUT_OF_MEMORY; goto done; }
+
+     for (j = 0; j < n; ++j)
+         if (sxu[j] < sxl[j]) {
+             t = sxl[j]; 
+             sxl[j] = sxu[j]; 
+             sxu[j] = t;
+     }
+
+    xl = sxl;
     xu = sxu;
 
-    rhobeg = dx[0] / s[0]; /* equals all other dx[i] after rescaling */
+    rhobeg = fabs(dx[0] / s[0]); /* equals all other dx[i] after rescaling */
 
     calfun_data.s = s;
     calfun_data.xs = xs;
