chiark / gitweb /
added simple convex test function
[nlopt.git] / test / testfuncs.c
index fbfbbbcbbb032a71fa64c6d675666ce507523236..5e29d92f873c7973ff974fb630abc1fa205758a7 100644 (file)
@@ -270,6 +270,24 @@ static const double sixhumpcamel_lb[2] = {-5,-5};
 static const double sixhumpcamel_ub[2] = {5,5};
 static const double sixhumpcamel_xmin[2] = {0.08984, -0.71266};
 
+/****************************************************************************/
+static double convexcosh_f(int n, const double *x, double *grad, void *data)
+{
+     int i;
+     double f = 1;
+     UNUSED(data);
+     for (i = 0; i < n; ++i)
+         f *= cosh((x[i] - i) * (i+1));
+     if (grad)
+         for (i = 0; i < n; ++i)
+              grad[i] = f * tanh((x[i] - i) * (i+1)) * (i+1);
+     RETURN(f);
+}
+
+static const double convexcosh_lb[10] = {-1,0,0,0,0,0,0,0,0,0};
+static const double convexcosh_ub[10] = {2,3,6,7,8,10,11,13,14,16};
+static const double convexcosh_xmin[10] = {0,1,2,3,4,5,6,7,8,9};
+
 /****************************************************************************/
 /****************************************************************************/
 
@@ -318,5 +336,8 @@ const testfunc testfuncs[NTESTFUNCS] = {
        0.0, "Griewank function" },
      { sixhumpcamel_f, NULL, 1, 2,
        sixhumpcamel_lb, sixhumpcamel_ub, sixhumpcamel_xmin,
-       -1.03163, "Six-hump camel back function" }
+       -1.03163, "Six-hump camel back function" },
+     { convexcosh_f, NULL, 1, 10,
+       convexcosh_lb, convexcosh_ub, convexcosh_xmin,
+       1.0, "Convex product of cosh functions" }
 };