Divergence
By Corinne Manogue
Copyright 1997 Corinne Manogue

Clear[x,y,z]

Needs["VectorAnalysis`"]

Element[x,Reals];
Element[y,Reals];
Element[z,Reals];

v1={0,1,0}

VectorPlot3D[v1,{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->10,VectorScale->Small,AxesLabel->{x,y,z},ViewPoint->{0,0,Infinity}]

f1=Div[v1,Cartesian[x,y,z]]

Now try another vector field:

v2={x,y,0}

VectorPlot3D[v2,{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->10,VectorScale->Small,AxesLabel->{x,y},ViewPoint->{0,0,Infinity}]

f2=Div[v2,Cartesian[x,y,z]]

Now try another field:

v3={0,Exp[-y^2],0}

VectorPlot3D[v3,{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->10,VectorScale->Small,AxesLabel->{x,y,z},ViewPoint->{0,0,Infinity}]

f3=Div[v3,Cartesian[x,y,z]]

Plot3D[f3,{x,-3,3},{y,-3,3},ColorFunction->Hue,AxesLabel->{x,y}]

Now try another vector field:

v4={0,Exp[-x^2],0}

VectorPlot3D[v4,{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->10,VectorScale->Small,AxesLabel->{x,y,z},ViewPoint->{0,0,Infinity}]

f4=Div[v4,Cartesian[x,y,z]]

Now try another vector field:

v5={-y,x,0}

VectorPlot3D[v5,{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->10,VectorScale->Small,AxesLabel->{x,y,z},ViewPoint->{0,0,Infinity}]

f5=Div[v5,Cartesian[x,y,z]]

Now try another vector field:

v6={x,y,0}

VectorPlot3D[v6,{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->10,VectorScale->Small,AxesLabel->{x,y,z},ViewPoint->{0,0,Infinity}]

f6=Div[v6,Cartesian[x,y,z]]

Now try another vector field:

v7={x/(x^2+y^2),y/(x^2+y^2),0}

VectorPlot3D[v7,{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->10,VectorScale->Small,AxesLabel->{x,y,z},ViewPoint->{0,0,Infinity}]

f7=Div[v7,Cartesian[x,y,z]]

Simplify[%]

Now try another vector field:

v0={Sin[x*y],y,0}

VectorPlot3D[v0,{x,-2,2},{y,-2,2},{z,-2,2},VectorPoints->10,VectorScale->Small,AxesLabel->{x,y,z},ViewPoint->{0,0,Infinity}]

f0=Div[v0,Cartesian[x,y,z]]

Plot3D[f0,{x,-2,2},{y,-2,2},ColorFunction->Hue,AxesLabel->{x,y},BoxRatios->Automatic]

Now try another vector field.

v8={x,y,z}

VectorPlot3D[v8,{x,-5,5},{y,-5,5},{z,-5,5},VectorPoints->5,VectorScale->Small,Axes->True,AxesLabel->{x,y,z}]

f8=Div[{x,y,z},Cartesian[x,y,z]]

Now try another vector field:

v9=1/((x^2+y^2+z^2)^(1/2))

Efield=Grad[-v9,Cartesian[x,y,z]]

VectorPlot3D[Efield,{x,-5,5},{y,-5,5},{z,-5,5},VectorPoints->5,VectorScale->Small,Axes->True,AxesLabel->{x,y,z}]

f9=Div[Efield,Cartesian[x,y,z]]

Simplify[%]

Div[{1/r^2,0,0},Spherical[r,θ,ϕ]]