code: static public double rastrigin(double[] x) {
  
      double sum = 0.0;
  
      for (int i = 0; i < x.length; i++) {
        sum += (x[i] * x[i]) - (10.0 * Math.cos(PIx2 * x[i])) + 10.0;
      }
  
      return (sum);
    }
docs: Rastrigin's function