The function of which to find the gradient.
The point at which to find the gradient.
A "characteristic scale" over which the function changes significantly. (optional)
A buffer of the same length as x, for the returned gradient vector. (optional)
// Let's find the gradient of f(x,y) = x exp(y) at // the point p = (2,1). real f(real[] x) { return x[0] * exp(x[1]); } real[] p = [2.0L, 1.0L]; auto g = gradient(&f, p);
Calculate the gradient of a function of several variables.
This function calculates a central-difference approximation to the gradient of a function f. The error in the result is, at best, on the order of sqrt(real.epsilon). The function f is evaluated 2n times, where n is the length of the vector x.