divergence

Divergence of a vector field.

Category: Graphics > 2-D and 3-D Plots

Syntax

div = divergence(X, Y, U, V)

Divergence of a 2-D field.

div = divergence(X, Y, Z, U, V, W)

Divergence of a 3-D field.

Description

Divergence measures how much a field spreads out from each point: positive at a source, negative at a sink and zero for an incompressible flow. It is computed with finite differences on the grid, so it is exact for fields that are linear in the coordinates.

Input arguments

X, Y, Z
Grid coordinates, as from meshgrid.
U, V, W
Components of the vector field, with the size of the grid.

Output arguments

div
Array of the grid size with dU/dx + dV/dy (+ dW/dz).

Example

Radial field

[X, Y] = meshgrid(1:4);
d = divergence(X, Y, X, Y)
Output
d = 4×4

     2     2     2     2
     2     2     2     2
     2     2     2     2
     2     2     2     2

See also

curl gradient del2 quiver meshgrid