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.
精彩评论