public double f_to_minimize(double x[]) {

      double f,sq1,sq2,sq3,f1,f2,f3,f4,fac,c1,c2,s1,s2;
      double theta,x1,x2,x3,x4;

      if (id_f_to_min == 0) {

         f = x[1]*x[1];

      } else if (id_f_to_min == 1) {

         sq1 = (x[1] - c)*(x[1] - c);
         sq2 = (x[2] - d)*(x[2] - d);

         f = sq1 + sq2;

      } else if (id_f_to_min == 2) {

         sq1 = (x[1] - c)*(x[1] - c);
         sq2 = (x[2] - d)*(x[2] - d);
         sq3 = (x[3] - e)*(x[3] - e);

         f = sq1 + sq2 + sq3;

      } else if (id_f_to_min == 3) {

         f1 = 10.0*(x[2] - x[1]*x[1]);
         f2 = 1.0 - x[1];
         f3 = 10.0*(x[4] - x[3]*x[3]);
         f4 = 1.0 - x[3];

         f = f1*f1 + f2*f2 + f3*f3 + f4*f4;

      } else if (id_f_to_min == 4) {

         f1 = x[1] + 10.0*x[2];
         f2 = Math.sqrt(5.0)*(x[3] - x[4]);
         fac = x[2] - 2.0*x[3];
         f3 = fac*fac;
         fac = x[1] - x[4];
         f4 = Math.sqrt(10.0)*fac*fac;

         f = f1*f1 + f2*f2 + f3*f3 + f4*f4;

      } else if (id_f_to_min == 5) {

         c1 = Math.cos(x[1]);
         c2 = Math.cos(x[2]);

         s1 = Math.sin(x[1]);
         s2 = Math.sin(x[2]);

         f1 = 1.0 - (c1 + (1.0 - c1) - s1);
         f2 = 2.0 - ((c1 + 2.0*(1 - c2) - s2) +
                     (c2 + 2.0*(1 - c2) - s2));

         f = f1*f1 + f2*f2;

      } else if (id_f_to_min == 6) {


         if (x[1] > 0.0) {

            theta = one_d_twopi*Math.atan(x[2]/x[1]);

         } else {

            theta = one_d_twopi*Math.atan(x[2]/x[1]) + .5;

         }

         f1 = 10.0*(x[3] - 10.0*theta);
         f2 = 10.0*(Math.sqrt(x[1]*x[1] + x[2]*x[2]) - 1.0);
         f3 = x[3];

         f = f1*f1 + f2*f2 + f3*f3;

      } else {

         x1 = x[1];
         x2 = x[2];
         x3 = x[3];
         x4 = x[4];

         f = 100.0*(x1*x1 - x2)*(x1*x1 - x2) + (1.0 - x1)*(1.0 - x1) +
              90.0*(x3*x3 - x4)*(x3*x3 - x4) + (1.0 - x3)*(1.0 - x3) +
              10.1*((1.0 - x2)*(1.0 - x2) + (1.0 - x4)*(1.0 - x4)) +
              19.8*(1.0 - x2)*(1.0 - x4);

      }

      return f;         

   }