Skip to content

divergence

general · scripts/general/divergence.m

: div = divergence (x, y, z, fx, fy, fz)
: div = divergence (fx, fy, fz)
: div = divergence (x, y, fx, fy)
: div = divergence (fx, fy)

Numerical divergence of a sampled vector field.

The field components fx, fy and, in three dimensions, fz are arrays of the same size holding the field on a grid; the result is the sum of the partial derivative of each component along its own axis, estimated with gradient.

div F = dFx/dx + dFy/dy (+ dFz/dz)

The grid coordinates may be supplied as x, y and z (arrays from meshgrid, or vectors along each axis); without them unit spacing is assumed.