Extending 'gradient' to handle function handles

Søren Hauberg soren at hauberg.org
Fri Feb 1 13:17:30 CST 2008


Hi,
  The 'gradient' function currently only allows you to estimate the
gradient of discrete data (i.e. data in a matrix). I think it would make
sense if the 'gradient' function was also defined for function handles,
such that you could do something like this:

  f = @sin;
  df_dx = gradient(f, 0); # calculates the gradient at x = 0

Is this something there's interest in? The attached patch implements
this using a simple central difference scheme. For multi-dimensional
functions the API is like this:

  f = @(x,y) sin(x).*cos(x);
  [dx, dy] = gradient(f, rand(7,2)); # calculate the gradient in 7
random points

Thoughts?
Søren
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gradient.patch
Type: text/x-patch
Size: 1978 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080201/e6e574b4/attachment.bin 


More information about the Octave-maintainers mailing list