divergence
Compute divergence of vector field
Syntax
Description
computes thenumerical divergenceof a 3-D vector field with vector componentsdiv
= divergence(X
,Y
,Z
,Fx
,Fy
,Fz
)Fx
,Fy
, andFz
.
The arraysX
,Y
, andZ
, which define the coordinates for the vector componentsFx
,Fy
, andFz
, must be monotonic, but do not need to be uniformly spaced.X
,Y
, andZ
must be 3-D arrays of the same size, which can be produced bymeshgrid
.
assumes a default grid of sample points. The default grid pointsdiv
= divergence(Fx
,Fy
,Fz
)X
,Y
, andZ
are determined by the expression[X,Y,Z] = meshgrid(1:n,1:m,1:p)
, where[m,n,p] = size(Fx)
. Use this syntax when you want to conserve memory and are not concerned about the absolute distances between points.
computes thenumerical divergenceof a 2-D vector field with vector componentsdiv
= divergence(X
,Y
,Fx
,Fy
)Fx
andFy
.
The matricesX
andY
, which define the coordinates forFx
andFy
, must be monotonic, but do not need to be uniformly spaced.X
andY
must be 2-D matrices of the same size, which can be produced bymeshgrid
.
Examples
Input Arguments
More About
Algorithms
divergence
computes the partial derivatives in its definition by using finite differences. For interior data points, the partial derivatives are calculated usingcentral difference. For data points along the edges, the partial derivatives are calculated usingsingle-sided (forward) difference.
For example, consider a 2-D vector fieldFthat is represented by the matricesFx
andFy
at locationsX
andY
with sizem
-by-n
. The locations are 2-D grids created by[X,Y] = meshgrid(x,y)
, wherex
is a vector of lengthn
andy
is a vector of lengthm
.divergence
then computes the partial derivatives∂Fx/ ∂xand∂Fy/ ∂yas
dFx(:,i) = (Fx(:,i+1) - Fx(:,i-1))/(x(i+1) - x(i-1))
anddFy(j,:) = (Fy(j+1,:) - Fy(j-1,:))/(y(j+1) - y(j-1))
for interior data points.
dFx(:,1) = (Fx(:,2) - Fx(:,1))/(x(2) - x(1))
anddFx(:,n) = (Fx(:,n) - Fx(:,n-1))/(x(n) - x(n-1))
for data points at the left and right edges.
dFy(1,:) = (Fy(2,:) - Fy(1,:))/(y(2) - y(1))
anddFy(m,:) = (Fy(m,:) - Fy(m-1,:))/(y(m) - y(m-1))
for data points at the top and bottom edges.
The numerical divergence of the vector field is equal todiv = dFx + dFy
.