gradient

Numerical gradient.

Syntax

  • FX = gradient(F)

  • [FX, FY] = gradient(F)

  • [FX, FY, FZ, ..., FN] = gradient(F)

  • [...] = gradient(F, h)

  • [...] = gradient(F, hx, hy, ... , hN)

Input argument

  • F - Input array: vector, matrix or multidimensional array.

  • h - Uniform spacing between points: scalar or 1 (default).

  • hx, hy, ..., hN - Spacing between points: vector, scalar or 1 (default).

Output argument

  • FX, FY, FZ, ..., FN - Numerical gradients: array.

Description

gradient(F) calculates the one-dimensional numerical gradient of the vector or matrix F.

The output FX represents the differences in the x (horizontal) direction, corresponding to ∂F/∂x.

It assumes that the spacing between points is 1.

gradient(F, h) allows for specifying a uniform spacing h between points in each direction.

This uniform spacing can also be individually specified for each dimension of F using gradient(F, hx, hy, ..., hN).

Example

[X, Y] = meshgrid(-2:0.2:2);
Z = X .* exp(-X.^2 - Y.^2);
[U, V] = gradient(Z, 0.2, 0.2);

See also

diff.

History

Author

Allan CORNET

Last updated