title: GNU GSL C++ error code 27 for Multidimensional Minimization: iteration is not making progress towards solution
body: <p>I am trying to find the minimum of the function using GNU scientific library, package Multidimensional Minimization. The method I am using is Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm which is implemented in function </p>
  
  <pre><code>gsl_multimin_fdfminimizer_vector_bfgs2
  </code></pre>
  
  <p>Unfortunately, after the first iteration with</p>
  
  <pre><code>gsl_multimin_fdfminimizer_iterate
  </code></pre>
  
  <p>I receive an error with code 27: iteration is not making progress towards solution.</p>
  
  <p>I tried several initial points and different tolerance/step combinations, but still the same error pops up. Could you please tell me what could be the culprit here?</p>
  
  <p>The idea is to find a potential energy minimum for a cluster of 13 atoms. The energy is calculated in function my_f, where X,Y and Z are atoms coordinates. The parameters used are</p>
  
  <pre><code>#define uA 0.1221
  #define uXi 1.316
  #define uP  8.612
  #define uQ  2.516
  #define uR0 2.8637
  </code></pre>
  
  <p>The function I am trying to minimize is Gupta-Potential for Aluminum 13 atoms cluster:</p>
  
  <p><strong>// HERE IS MY GUPTA POTENTIAL//</strong></p>
  
  <pre><code>double
        my_f (const gsl_vector *v, void *params)
       {
         double *p = (double *)params;
          int ii,jj;
          double vv = 0;
          double sum1 = 0;
          double sum2 = 0;
  
            for(ii=1;ii&lt;=NN;ii++){
            X[ii]=gsl_vector_get (v, 3*ii-3);
            Y[ii]=gsl_vector_get (v, 3*ii-2);
            Z[ii]=gsl_vector_get (v, 3*ii-1 );
           }
  
          for(ii = 1; ii &lt;= NN; ii++){
                  sum1 = 0;
                  for(jj = 1; jj &lt;= NN; jj++){
  
                          if(jj!=ii){
                                  sum1 += uA*exp(0 - uP*((rr(ii,jj)/uR0) - 1.));
                          }
                  }
                  sum2 = 0;
                  for(jj = 1; jj &lt;= NN; jj++){
                          if(jj!=ii){
                                  sum2 += uXi*uXi*exp(0 - 2*uQ*((rr(ii,jj)/uR0) - 1.));
                          }
                  }
                  vv += sum1 - sqrt(sum2);
          }
          return vv;
   }
  </code></pre>
  
  <p><strong>// HERE ARE MY GRADIENT FUNCTIONS//</strong></p>
  
  <pre><code>double dVdr(int ii, int jj){
          double vr;
          double sum1 = 0;
          double sum2 = 0;
          int kk;
  
          vr = 0. - 2.*uA*(uP/uR0)*exp(0. - uP*((rr(ii,jj)/uR0) - 1.));
  
          for(kk = 1; kk &lt;= NN; kk++){
                  if(kk != ii){
                          sum1 += uXi*uXi*exp(0 - 2*uQ*((rr(ii,kk)/uR0) - 1.));
                  }
                  if(kk != jj){
                          sum2 += uXi*uXi*exp(0 - 2*uQ*((rr(kk,jj)/uR0) - 1.));
                  }
          }
  
          vr -= 0.5*uXi*uXi*(0. - 2.*uQ/uR0)*exp(0. - 2.*uQ*((rr(ii,jj)/uR0) - 1.))*( (1./sqrt(sum1)) + (1./sqrt(sum2)) );
  
          return vr;
  }
  
  //-----------------------------------------------
   void Force(int jj, double &amp; fx, double &amp; fy, double &amp; fz){
          int mm;
          double dxx, dyy, dzz, r;
          fx = 0;
          fy = 0;
          fz = 0;
     for(mm = 1; mm &lt;= NN; mm++){
  
      if(mm != jj){
                          dxx = X[mm] - X[jj];
                          dyy = Y[mm] - Y[jj];
                          dzz = Z[mm] - Z[jj];
  
       r = sqrt(dxx*dxx + dyy*dyy + dzz*dzz);
       fx += dVdr(mm,jj)*(dxx)/r;
       fy += dVdr(mm,jj)*(dyy)/r;
       fz += dVdr(mm,jj)*(dzz)/r;
     }
     }
  }
  //--------------------------------------------
   void
       my_df (const gsl_vector *v, void *params,
              gsl_vector *df)
       {
         int ii;
         double fx,fy,fz;
         double *p = (double *)params;
  
            for(ii=1;ii&lt;=NN;ii++){
  
            X[ii]=gsl_vector_get (v, 3*ii-3);
            Y[ii]=gsl_vector_get (v, 3*ii-2);
            Z[ii]=gsl_vector_get (v, 3*ii-1 );
           }
  
            for(ii=1;ii&lt;=NN;ii++){
            Force(ii,fx,fy,fz);
            gsl_vector_set(df, 3*ii-3, fx );
            gsl_vector_set(df, 3*ii-2, fy );
            gsl_vector_set(df, 3*ii-1, fz );
           }
       }
  //----------------------------------
  </code></pre>