31. The divergence theorem
§12.8's Stokes' theorem related circulation around a boundary curve to curl summed across a spanning surface. This lesson completes the pattern one dimension further up: relating flux through a boundary surface to divergence summed throughout the enclosed solid — and it finally proves the coincidence flagged (but not yet explained) at the end of §12.7.
The theorem
Let E be a solid region with boundary surface S, oriented with the outward normal. Then \iint_S\vec F\cdot d\vec S=\iiint_E\text{div}\,\vec F\,dV
Total flux out of a closed surface equals the total divergence summed throughout the volume it encloses. This is exactly the same structural pattern as Green's theorem (boundary circulation equals interior curl) and Stokes' theorem (boundary circulation equals interior curl-flux), one more level up: boundary flux equals interior divergence. All three theorems say the same thing in a genuinely unified sense — a local differential quantity (Q_x-P_y, curl, or divergence), summed throughout an interior, always equals a boundary integral one dimension down.
Why this makes physical sense
Divergence (§12.5) measures net outward flow per unit volume at a point — how much a fluid is locally expanding (a source) or contracting (a sink) right there. Summing that local source strength throughout an entire solid should give the total amount of fluid being generated inside — and every bit of fluid generated inside has to eventually exit through the boundary somewhere, since it can't simply vanish or pile up without limit. Total flux out equals total source strength in is exactly the divergence theorem's physical content, and it's essentially a conservation-of-mass argument, dressed in calculus.
Closing §12.7's loose thread
§12.7 computed the flux of \vec F(x,y,z)=\langle x,y,z\rangle through a sphere of radius R directly, getting 4\pi R^3, and noted — without proof — that this equalled 3 times the sphere's volume. The divergence theorem is exactly why:
\text{div}\,\vec F=\frac\partial{\partial x}(x)+\frac\partial{\partial y}(y)+\frac\partial{\partial z}(z)=1+1+1=3
(computed in §12.5's "Your turn," problem 1, for this exact field)
\iiint_E\text{div}\,\vec F\,dV=\iiint_E3\,dV=3\cdot\text{Volume}(E)=3\cdot\frac43\pi R^3=4\pi R^3
Matching §12.7's direct computation exactly — but derived here without ever touching a surface parametrization at all, purely from \text{div}\,\vec F=3 being a constant and volume being elementary. This is the practical payoff of the divergence theorem: it frequently converts a genuinely painful surface integral into a much simpler triple integral, or (as here) into pure arithmetic once divergence turns out to be constant.
Doing it in Python
Verifying the divergence theorem for $\vec F(x,y,z)=\langle x,y,z\rangle$ over a ball of radius R — computing both sides independently:
import sympy as sp
x, y, z, rho, phi, theta, R = sp.symbols('x y z rho phi theta R', positive=True)
# right side: triple integral of divergence over the ball
div_F = sp.diff(x, x) + sp.diff(y, y) + sp.diff(z, z)
print(f"div F = {div_F}")
triple_integral = sp.integrate(
sp.integrate(
sp.integrate(div_F * rho**2 * sp.sin(phi), (rho, 0, R)),
(phi, 0, sp.pi)
),
(theta, 0, 2*sp.pi)
)
print(f"triple integral of div F = {sp.simplify(triple_integral)}")
# left side: flux, from section 12.7's direct computation
flux_from_section_12_7 = 4 * sp.pi * R**3
print(f"flux (from 12.7's direct surface computation) = {flux_from_section_12_7}")
print(f"match: {sp.simplify(triple_integral - flux_from_section_12_7) == 0}")
Using the divergence theorem to shortcut a flux computation for a more complicated field, where direct surface integration would be painful:
import sympy as sp
x, y, z = sp.symbols('x y z')
F = sp.Matrix([x**3, y**3, z**3]) # a field with a genuinely messy surface integral
div_F = sp.diff(F[0], x) + sp.diff(F[1], y) + sp.diff(F[2], z)
print(f"div F = {div_F}")
rho, phi, theta = sp.symbols('rho phi theta', positive=True)
div_spherical = div_F.subs({
x: rho*sp.sin(phi)*sp.cos(theta),
y: rho*sp.sin(phi)*sp.sin(theta),
z: rho*sp.cos(phi)
})
div_spherical = sp.expand_trig(sp.simplify(div_spherical))
flux = sp.integrate(
sp.integrate(
sp.integrate(div_spherical * rho**2 * sp.sin(phi), (rho, 0, 1)),
(phi, 0, sp.pi)
),
(theta, 0, 2*sp.pi)
)
print(f"flux through the unit sphere = {sp.simplify(flux)}")
Confirming the div-of-curl identity (§12.5) via the divergence theorem — the flux of any curl field through a closed surface is always zero:
import sympy as sp
x, y, z = sp.symbols('x y z')
G = sp.Matrix([x**2*y, y**2*z, z**2*x]) # an arbitrary field
curl_G = sp.Matrix([
sp.diff(G[2], y) - sp.diff(G[1], z),
sp.diff(G[0], z) - sp.diff(G[2], x),
sp.diff(G[1], x) - sp.diff(G[0], y)
])
div_of_curl = sp.diff(curl_G[0], x) + sp.diff(curl_G[1], y) + sp.diff(curl_G[2], z)
print(f"div(curl G) = {sp.simplify(div_of_curl)}")
print("by the divergence theorem, flux of curl G through ANY closed surface is 0")
Worked example
Verify the divergence theorem for $\vec F(x,y,z)=\langle x,y,z\rangle$ over the ball of radius R.
Divergence: \text{div}\,\vec F=1+1+1=3, a constant.
Right side (triple integral):
\iiint_E3\,dV=3\cdot\text{Volume(ball)}=3\cdot\frac43\pi R^3=\boxed{4\pi R^3}
Left side (flux, from §12.7's direct surface computation): \boxed{4\pi R^3}.
Sanity check. Both sides match exactly, and — more importantly — the right side took a single line of arithmetic once divergence was known to be constant, versus §12.7's full parametrized-surface computation (tangent vectors, cross product, trigonometric simplification, two nested integrals). This is the divergence theorem's real value: recognizing that a flux problem can be converted to a (often much simpler) volume problem, exactly the trade Green's theorem offered for circulation versus area two-dimensionally. ✓
Your turn
1. Find the flux of \vec F(x,y,z)=\langle2x,2y,2z\rangle through a sphere of radius 3, using the divergence theorem (don't parametrize any surface).
2. Using the divergence theorem, explain why the flux of any constant vector field (like \vec F=\langle5,-2,7\rangle everywhere) through any closed surface is always exactly 0.
3. True or false: the divergence theorem requires the enclosed solid E to have a simple shape, like a ball or a box.
Solutions
1. \text{div}\,\vec F=2+2+2=6.
\text{Flux}=\iiint_E6\,dV=6\cdot\frac43\pi(3)^3=6\cdot36\pi=\boxed{216\pi}
2. For a constant field \vec F=\langle a,b,c\rangle, $\text{div}\,\vec F=\frac{\partial a}{\partial x}+\frac{\partial b}{\partial y}+\frac{\partial c}{\partial z}=0+0+0=0$ (the partial derivative of any constant is always 0). By the divergence theorem, \text{Flux}=\iiint_E0\,dV=0 for any enclosed solid E at all — a uniform field has no sources or sinks anywhere, so exactly as much flows in one side of any closed surface as flows out the other, everywhere, always.
3. False. Exactly like Stokes' theorem in §12.8, the divergence theorem is stated for a general solid region with a well-behaved (closed, piecewise-smooth) boundary surface — balls and boxes are simply the easiest examples to compute by hand, not a restriction on where the theorem applies. It holds for arbitrarily irregular solids, provided the boundary surface is well-defined and orientable.
Check yourself in code
Verify the divergence theorem for \vec F(x,y,z)=\langle x,y,z\rangle over the ball of radius R: compute the divergence and the triple integral, and compare to the flux 4\pi R^3 from §12.7.
Print exactly this:
div F = 3
triple integral = 4*pi*R**3
match: True
import sympy as sp
x, y, z, rho, phi, theta, R = sp.symbols('x y z rho phi theta R', positive=True)
div_F = sp.diff(x, x) + sp.diff(y, y) + sp.diff(z, z)
print("div F = ...")
triple_integral = sp.integrate(
sp.integrate(
sp.integrate(div_F * rho**2 * sp.sin(phi), (rho, 0, R)),
(phi, 0, sp.pi)
),
(theta, 0, 2*sp.pi)
)
print("triple integral = ...")
flux_from_12_7 = 4 * sp.pi * R**3
print("match: ...")
import sympy as sp
x, y, z, rho, phi, theta, R = sp.symbols('x y z rho phi theta R', positive=True)
div_F = sp.diff(x, x) + sp.diff(y, y) + sp.diff(z, z)
print(f"div F = {div_F}")
triple_integral = sp.integrate(
sp.integrate(
sp.integrate(div_F * rho**2 * sp.sin(phi), (rho, 0, R)),
(phi, 0, sp.pi)
),
(theta, 0, 2*sp.pi)
)
print(f"triple integral = {sp.simplify(triple_integral)}")
flux_from_12_7 = 4 * sp.pi * R**3
print(f"match: {sp.simplify(triple_integral - flux_from_12_7) == 0}")
The divergence theorem, $\iint_S\vec F\cdot d\vec S=\iiint_E\text{div}\,\vec F\,dV$, closes the pattern begun by Green's and Stokes' theorems: total flux out of a closed surface equals total divergence summed throughout the enclosed solid — a calculus statement of conservation of mass. It finally explains §12.7's 4\pi R^3=3\timesvolume coincidence directly, and more generally trades a painful surface-parametrization computation for a frequently much simpler triple integral, exactly the way Green's theorem traded circulation for area two dimensions down.
Next, and last: a short advanced look at how Green's, Stokes', and the divergence theorem — three seemingly separate results — are secretly one single theorem, stated once in the unifying language of differential forms.