- •If the values along the first non-singleton dimension contain more
- •If the values along the first non-singleton dimension contain more
- •Finite differences
- •In the z direction. Gradient(f,h), where h is a scalar,
- •Is a scalar, it gives the spacing between points in the
- •Correlation
- •Variances for each column, and sqrt(diag(cov(X))) is a vector
- •Filtering and convolution
- •Iddata/detrend
Finite differences
<diff> - Difference and approximate derivative.
DIFF Difference and approximate derivative.
DIFF(X), for a vector X, is [X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)].
DIFF(X), for a matrix X, is the matrix of row differences,
[X(2:n,:) - X(1:n-1,:)].
DIFF(X), for an N-D array X, is the difference along the first
non-singleton dimension of X.
DIFF(X,N) is the N-th order difference along the first non-singleton
dimension (denote it by DIM). If N >= size(X,DIM), DIFF takes
successive differences along the next non-singleton dimension.
DIFF(X,N,DIM) is the Nth difference function along dimension DIM.
If N >= size(X,DIM), DIFF returns an empty array.
Examples:
h = .001; x = 0:h:pi;
diff(sin(x.^2))/h is an approximation to 2*cos(x.^2).*x
diff((1:10).^2) is 3:2:19
If X = [3 7 5
0 9 2]
then diff(X,1,1) is [-3 2 -3], diff(X,1,2) is [4 -2
9 -7],
diff(X,2,2) is the 2nd order difference along the dimension 2, and
diff(X,3,2) is the empty matrix.
See also gradient, sum, prod.
Overloaded methods:
char/diff
fints/diff
iddata/diff
localtruncps/diff
localpspline/diff
localpoly/diff
umat/diff
ndlft/diff
sym/diff
Reference page in Help browser
doc diff
<gradient> - Approximate gradient.
GRADIENT Approximate gradient.
[FX,FY] = GRADIENT(F) returns the numerical gradient of the
matrix F. FX corresponds to dF/dx, the differences in x (horizontal)
direction. FY corresponds to dF/dy, the differences in y (vertical)
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.
Note: The first output FX is always the gradient along the 2nd
dimension of F, going across columns. The second output FY is always
the gradient along the 1st dimension of F, going across rows. For the
third output FZ and the outputs that follow, the Nth output is the
gradient along the Nth dimension of F.
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
Class support for input F:
float: double, single
See also diff, del2.
Overloaded methods:
cgnormfunction/gradient
cglookuptwo/gradient
Reference page in Help browser
doc gradient
<del2> - Discrete Laplacian.
DEL2 Discrete Laplacian.
L = DEL2(U), when U is a matrix, is a discrete approximation of
0.25*del^2 u = (d^2u/dx^2 + d^2u/dy^2)/4. The matrix L is the same
size as U, with each element equal to the difference between an
element of U and the average of its four neighbors.
L = DEL2(U), when U is an N-D array, returns an approximation of
(del^2 u)/2/n, where n is ndims(u).
L = DEL2(U,H), where H is a scalar, uses H as the spacing between
points in each direction (H=1 by default).
L = DEL2(U,HX,HY), when U is 2-D, uses the spacing specified by HX
and HY. If HX is a scalar, it gives the spacing between points in
the x-direction. If HX is a vector, it must be of length SIZE(U,2)
and specifies the x-coordinates of the points. Similarly, if HY
