开发者

What does this statement mean in C? [closed]

开发者 https://www.devze.com 2023-04-08 01:58 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I am trying to understand the piece of code written in C and not sure I understand it fully.

Here is the function written in C:

int
gsl_multimin_diff (const gsl_multimin_function * f,
                   const gsl_vector * x, gsl_vector * g)
{
  size_t i, n = f->n;

  double h = GSL_SQRT_DBL_EPSILON;


  gsl_vector * x1 = gsl_vector_alloc (n);  /* FIXME: pass as argument */

  gsl_vector_memcpy (x1, x);

  for (i = 0; i < n; i++)
    {
      double fl, fh;

      double xi = gsl_vector_get (x, i);
      double dx = fabs(xi) * h;

      if (dx == 0.0) dx = h;    

     (x1, i, xi + dx);
      fh = GSL_MULTIMIN_FN_EVAL(f, x1)开发者_运维百科;

      gsl_vector_set (x1, i, xi - dx);
      fl = GSL_MULTIMIN_FN_EVAL(f, x1);

      gsl_vector_set (x1, i, xi);
      gsl_vector_set (g, i, (fh - fl) / (2.0 * dx));
    }

  gsl_vector_free (x1);

  return GSL_SUCCESS;
}

There is a line 14 in this code, which has this: (x1, i, xi + dx) What does it do? For referenc: x1 is the pointer to the function that allocates memory for a newly created vector. i - loop iterator xi - returning an element from the vector at position i dx is just a value. Thanks for your help!


It looks like there's something missing there. It should be function arguments. Otherwise it's a no-op - (x1, i, xi + dx) is a valid expression in C, but one that doesn't do anything. It just mentions x1, then mentions i, then mentions the sum of xi and dx.

0

精彩评论

暂无评论...
验证码 换一张
取 消