GRADIENT

 

 Approximate gradient.

  [PX,PY] = GRADIENT(Z,DX,DY) returns the numerical partial derivatives

  of matrix Z in matrices PX = dZ/dx and PY = dZ/dy.   DX and DY

  may be scalars containing the sample spacing in the X and Y

  directions, or they may be vectors containing all the explicit

  locations.

 

 

  [PX,PY] = GRADIENT(Z) assumes DX = DY = 1.

 

 

  If Y is a vector, GRADIENT(Y) and GRADIENT(Y,DX) return the one

  dimensional numerical derivative dY/dX.

 

 

  For example, try

     [x,y] = meshgrid(-2:.2:2, -2:.2:2);

     z = x .* exp(-x.^2 - y.^2);

     [px,py] = gradient(z,.2,.2);

     contour(z),hold on, quiver(px,py), hold off

 

 

  See also DIFF16RREU2, DEL216NX1U2, QUIVER1WVGFJ1, CONTOURXAOYTS.