Next: , Previous: deriv, Up: Gradient functions


4.3 Another numerical gradient function

Helptext:

numgradient(f, {args}, minarg)

Numeric central difference gradient of f with respect
to argument \"minarg\".
* first argument: function name (string)
* second argument: all arguments of the function (cell array)
* third argument: (optional) the argument to differentiate w.r.t.
	(scalar, default=1)

\"f\" may be vector-valued. If \"f\" returns
an n-vector, and the argument is a k-vector, the gradient
will be an nxk matrix

Example:
function a = f(x);
	a = [x'*x; 2*x];
endfunction
numgradient(\"f\", {ones(2,1)})
ans =

  2.00000  2.00000
  2.00000  0.00000
  0.00000  2.00000