Gradient, curl, divergence

Multivariable Calculus, Math 211, Carleton College, Fall 2021, Joshua R. Davis, jdavis@carleton.edu

Gradient (review)

Here is a scalar field z = f(x, y) on (R^2). Compare the contour plot to the gradient vector plot, to remind yourself that (at each point) the gradient points uphill, with magnitude indicating the steepness of the hill. Also, the gradient is perpendicular to the level set of f.

Clear[x, y, z];
f = Exp[-2.0 (x - 1)^2 - (y - 1)^2] + 1.5 Exp[-0.4 (x + 1)^2 - (y + 1)^2];
ContourPlot[f, {x, -2, 2}, {y, -2, 2}]
ff = Grad[f, {x, y}]
VectorPlot[ff, {x, -2, 2}, {y, -2, 2}]

And here’s Newtonian gravity with simplified constants. The level sets of f are spheres centered on the origin. Notice that the gradient is again perpendicular to the level set of f.

f = (x^2 + y^2 + z^2)^(-1 / 2);
ff = Grad[f, {x, y, z}]
VectorPlot3D[ff, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

Curl

Here is an arbitrary three-dimensional vector field.

Clear[x, y, z];
ff = {x^2 y, x Sin[z], y z};
VectorPlot3D[ff, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

Here is its curl. Try focusing on the point (-2, 1, 2). The curl vector there is the axis of rotation of the original vector field there.

gg = Curl[ff, {x, y, z}]
VectorPlot3D[gg, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

Here’s a two-dimensional example, which is easier to see.

ff = {Sin[y], Cos[y]};
VectorPlot[ff, {x, -Pi, Pi}, {y, -Pi, Pi}]

By extruding the two-dimensional example into  the third dimension, you get a three-dimensional vector field.

ff = {Sin[y], Cos[y], 0};
VectorPlot3D[ff, {x, -Pi, Pi}, {y, -Pi, Pi}, {z, -Pi, Pi}]

If you ask Mathematica to compute the curl of a two-dimensional vector field, it gives you the z component of the curl of the extruded three-dimensional vector field.

ff = {Sin[y], Cos[y]};
Curl[ff, {x, y}]
ff = {Sin[y], Cos[y], 0};
gg = Curl[ff, {x, y, z}]

Anyway, here’s what that curl looks like. Carefully compare this 3D plot of curl F to the plots of F above.

VectorPlot3D[gg, {x, -Pi, Pi}, {y, -Pi, Pi}, {z, -Pi, Pi}]

Here’s a two-dimensional example from an earlier Mathematica notebook. It describes the velocity field inside a shear zone.

l11 = 2;
l12 = 3;
l21 = 0;
l = {{l11, l12}, {l21, -l11}};
eig = Eigensystem[l];
If[eig[[1, 1]] < eig[[1, 2]],
	u = eig[[2, 1]],
	u = eig[[2, 2]]];
u = l.{u[[1]] / u[[2]], 1};
ff = l.{x, y};
VectorPlot[ff, {x, -2, 2}, {y, -1, 1}]

Somewhat surprisingly, the curl is constant. That’s a special feature of this shear zone model.

gg = Curl[{ff[[1]], ff[[2]], 0}, {x, y, z}]
VectorPlot3D[gg, {x, -2, 2}, {y, -1, 1}, {z, -1, 1}]

Divergence

Here is the two-dimensional shear zone velocity field again.

Clear[x, y, z];
l11 = 2;
l12 = 3;
l21 = 0;
l = {{l11, l12}, {l21, -l11}};
eig = Eigensystem[l];
If[eig[[1, 1]] < eig[[1, 2]],
	u = eig[[2, 1]],
	u = eig[[2, 2]]];
u = l.{u[[1]] / u[[2]], 1};
ff = l.{x, y};
VectorPlot[ff, {x, -2, 2}, {y, -1, 1}]

Its divergence is zero. Physically, divergence zero means that, for every region of the plane, the amount of material entering the region is balanced by the amount of material leaving the region. It’s a form of conservation of mass.

Div[ff, {x, y}]

Here are three two-dimensional examples, in which the vectors are parallel. The divergence can be positive, negative, or zero, depending on how the magnitudes of the vectors are changing.

ff = {2 + x, 0};
Div[ff, {x, y}]
VectorPlot[ff, {x, -2, 2}, {y, -2, 2}]

ff = {2, 0};
Div[ff, {x, y}]
VectorPlot[ff, {x, -2, 2}, {y, -2, 2}]

ff = {2 - x, 0};
Div[ff, {x, y}]
VectorPlot[ff, {x, -2, 2}, {y, -2, 2}]

Here’s a three-dimensional example, which is similar to, but not identical to, Newtonian gravity. Somewhat surprisingly, it has positive divergence everywhere the divergence is defined. To understand why, revisit the preceding example.

f = (x^2 + y^2 + z^2)^(-3 / 2);
ff = Grad[f, {x, y, z}];
Simplify[Div[ff, {x, y, z}]]
VectorPlot3D[ff, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

And here’s Newtonian gravity again. A very special feature of this vector field is that the divergence is zero.

f = (x^2 + y^2 + z^2)^(-1 / 2);
ff = Grad[f, {x, y, z}];
Simplify[Div[ff, {x, y, z}]]

Curl of gradient

Here is an arbitrary three-dimensional scalar field. We compute its gradient and then the curl of that gradient. We get 0.

Clear[x, y, z];
f = x^2 y + Cos[2 y^3 z];
ff = Grad[f, {x, y, z}]
Simplify[Curl[ff, {x, y, z}]]

It’s no accident that the curl of the gradient was 0. Go ahead and alter the definition of the scalar field. As long as you restrict yourself to decently nice functions, you should get 0 every time. If F is a gradient, then curl F = 0.

It is natural to ask whether the converse is true: If curl F = 0, then is there an f such that F = grad f? The answer depends on whether there are holes in the domain of F.

Here’s the crucial example. We build it by extruding a certain two-dimensional vector field, that we have studied in our homework, into the third dimension. Its curl is 0.

ff = {-y / (x^2 + y^2), x / (x^2 + y^2), 0};
Simplify[Curl[ff, {x, y, z}]]
VectorPlot3D[ff, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

However, one can prove that there is no potential function for this f. (Here’s how. Show that if the three-dimensional vector field had a potential function, then the two-dimensional version would necessarily have a potential function too --- contrary to what we proved in our homework.)

Divergence of curl

Here is an arbitrary three-dimensional vector field. We compute its curl and then the divergence of that curl. We get 0.

Clear[x, y, z];
ff = {x^2 y, x Sin[z], y z};
gg = Curl[ff, {x, y, z}]
Simplify[Div[gg, {x, y, z}]]

It’s no accident that the divergence of the curl was 0. Go ahead and alter the definition of the vector field. As long as you restrict yourself to decently nice functions, you should get 0 every time. If G is a curl, then div G = 0.

It is natural to ask whether the converse is true: If div G = 0, then is there an F such that G = curl F? The answer depends on whether there are holes in the domain of G. Here’s the crucial example. It is a scalar multiple of the Newtonian gravitational force field.

gg = {x, y, z} / (x^2 + y^2 + z^2)^(3 / 2)
Simplify[Div[gg, {x, y, z}]]
VectorPlot3D[gg, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

However, one can prove that there is no F, whose curl is this G. (Here’s how, using some material that we haven’t studied quite yet. Using Stokes’s theorem, compute the flux of G across the unit sphere. You get a positive answer. But computing the flux of curl F across the same sphere must give an answer of 0. So G cannot equal curl F.)