1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
|
help gradient
GRADIENT Approximate gradient.
[FX,FY] = GRADIENT(F) returns the numerical gradient of the
matrix F. FX corresponds to dF/dx, the differences in the
x (column) direction. FY corresponds to dF/dy, the differences
in the y (row) direction. The spacing between points in each
direction is assumed to be one. When F is a vector, DF = GRADIENT(F)
is the 1-D gradient.
[FX,FY] = GRADIENT(F,H), where H is a scalar, uses H as the
spacing between points in each direction.
[FX,FY] = GRADIENT(F,HX,HY), when F is 2-D, uses the spacing
specified by HX and HY. HX and HY can either be scalars to specify
the spacing between coordinates or vectors to specify the
coordinates of the points. If HX and HY are vectors, their length
must match the corresponding dimension of F.
[FX,FY,FZ] = GRADIENT(F), when F is a 3-D array, returns the
numerical gradient of F. FZ corresponds to dF/dz, the differences
in the z direction. GRADIENT(F,H), where H is a scalar,
uses H as the spacing between points in each direction.
[FX,FY,FZ] = GRADIENT(F,HX,HY,HZ) uses the spacing given by
HX, HY, HZ.
[FX,FY,FZ,...] = GRADIENT(F,...) extends similarly when F is N-D
and must be invoked with N outputs and either 2 or N+1 inputs.
Examples:
[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 |