The Divergence of a Vector Field
Measuring how much a field spreads out - sources, sinks, and the continuity equation - Kaplan §3.4
Prereq: §3.3 The Gradient Field
Watch the particles. Is fluid being created somewhere, destroyed, or just pushed around?
Nine Derivatives, One Number
Back in §3.3, we took a scalar field $f$ and computed its gradient - a vector of three partial derivatives. Now we have a vector field $\mathbf{v} = (v_x, v_y, v_z)$, and each component is a function of $x, y, z$. So how many partial derivatives are there?
Three components, three variables each - that's nine partial derivatives, arranged naturally into a $3 \times 3$ matrix:
The diagonal entries (highlighted in orange) tell us something specific: each one measures how much the field stretches in that direction. $\partial v_x / \partial x$ tells us: "as we step in the $x$-direction, does the $x$-component of velocity increase?" If yes, the field is pulling things apart along $x$.
We'll use the diagonal right now. The six off-diagonal entries? They measure rotation. That's the curl - §3.5.
The Divergence Formula
Sum up the diagonal. That's the divergence:
The notation $\nabla \cdot \mathbf{v}$ isn't just a symbol - it's a genuine dot product. The nabla operator $\nabla = \left(\frac{\partial}{\partial x}, \frac{\partial}{\partial y}, \frac{\partial}{\partial z}\right)$ "dots" with $\mathbf{v} = (v_x, v_y, v_z)$, giving us a scalar.
Worked example. Take $\mathbf{v} = x^2\,\mathbf{i} - xy\,\mathbf{j} + xyz\,\mathbf{k}$. Then:
$\nabla \cdot \mathbf{v} = \dfrac{\partial(x^2)}{\partial x} + \dfrac{\partial(-xy)}{\partial y} + \dfrac{\partial(xyz)}{\partial z} = 2x + (-x) + xy = x + xy$
Notice: divergence eats a vector field and spits out a scalar field. At every point in space, we get a single number. What does that number mean?
What Divergence Measures
Think of a tiny box in a fluid flow. Fluid enters through some faces, exits through others. If more leaves than enters, there must be a source inside. If more enters than leaves, there's a sink. Divergence is the net outflow per unit volume:
- $\nabla \cdot \mathbf{v} > 0$ - net source. Fluid is being created (or density is decreasing).
- $\nabla \cdot \mathbf{v} \lt 0$ - net sink. Fluid is being absorbed.
- $\nabla \cdot \mathbf{v} = 0$ - incompressible. What flows in must flow out.
This idea is made precise by the continuity equation of fluid mechanics. If $\mathbf{u}$ is velocity and $\rho$ is density, then the vector $\mathbf{v} = \rho\mathbf{u}$ (mass flux) satisfies:
Mass can't appear from nowhere. If the divergence of mass flux is positive at a point, density there must be dropping - mass is leaving faster than it arrives. For an incompressible fluid ($\rho = \text{const}$), this simplifies beautifully to $\operatorname{div}\mathbf{u} = 0$.
The same structure appears in electrostatics. If $\mathbf{E}$ is the electric field and $\rho$ is the charge density, then $\operatorname{div}\mathbf{E} = 4\pi\rho$. Charges are the sources of the electric field - where there's positive charge, the field fans outward.
See It: Net Flux Through a Box
Here's the key idea made visible. We draw a vector field in the plane and place a small rectangle in it. For each edge of the rectangle, we compute the flux - how much of the field passes through that edge (the integral of $\mathbf{v} \cdot \mathbf{n}$ along the boundary, where $\mathbf{n}$ is the outward normal).
Drag the rectangle to explore different regions. Switch between field presets to build intuition.
Red = outflow (positive), Blue = inflow (negative). Drag the box to explore.
For the source field $(x, y)$: the net flux is always positive - wherever you put the box, more fluid leaves than enters. We can verify: $\nabla \cdot (x,y) = 1 + 1 = 2$ everywhere. The field has constant positive divergence.
For pure rotation $(-y, x)$: the net flux is zero. Rotation moves fluid around without creating or destroying it. Indeed $\nabla \cdot (-y, x) = 0 + 0 = 0$.
For shear $(y, 0)$: also zero net flux! $\nabla \cdot (y, 0) = 0 + 0 = 0$. The field slides layers past each other but doesn't compress or expand anything.
Properties of Divergence
Divergence behaves well with addition and scalar multiplication. The two key rules:
Linearity - divergence distributes over sums. No surprises here, since partial derivatives are linear.
This one is more interesting. When a scalar $f$ modulates a vector field $\mathbf{u}$, two things happen: the field itself might diverge ($f\,\nabla \cdot \mathbf{u}$), and the scalar's variation creates its own expansion or compression ($\nabla f \cdot \mathbf{u}$). This is the vector version of the product rule $(fg)' = fg' + f'g$.
Common mistake: forgetting the $\nabla f \cdot \mathbf{u}$ term. Students sometimes write $\nabla \cdot (f\mathbf{u}) = f\,\nabla \cdot \mathbf{u}$, pulling the scalar out like a constant. But $f$ varies in space - it's not a constant factor, so the product rule applies.
Final Review - When You See It, What to Reach For
We've built the formula and the intuition. Before practice, let's organize the tools so that on exam day a problem statement maps to a move almost automatically. The trick with divergence problems is recognizing which of three or four shapes is in front of you.
Here's the small menu. Read the left column as the prompt, the right as our move:
All three names mean the same thing: $\nabla \cdot \mathbf{u} = 0$. Compute it, simplify, confirm it cancels.
Two we've earned, two more from §3.6:
$$\nabla \cdot (\mathbf{u} + \mathbf{v}) = \nabla \cdot \mathbf{u} + \nabla \cdot \mathbf{v}$$ $$\nabla \cdot (f\,\mathbf{u}) = f\,(\nabla \cdot \mathbf{u}) + \nabla f \cdot \mathbf{u}$$ $$\nabla \cdot (\nabla f) = \nabla^2 f \;=\; f_{xx} + f_{yy} + f_{zz} \quad \text{(the Laplacian)}$$ $$\nabla \cdot (\nabla \times \mathbf{v}) = 0 \quad \text{(curl is always source-free)}$$The continuity equation:
$$\frac{\partial \rho}{\partial t} + \nabla \cdot (\rho\,\mathbf{u}) = 0.$$For incompressible flow ($\rho$ constant), this collapses to the cleaner $\nabla \cdot \mathbf{u} = 0$.
It turns out almost every §3.4 / §3.6 problem is one of these four moves wearing a costume. The rest is bookkeeping.
Traps to Watch For
The mistakes below are the ones that bite us under time pressure. Reading them now is cheap; rediscovering them on the exam isn't.
- Pulling $f$ through divergence. $\nabla \cdot (f\,\mathbf{u}) \ne f\,\nabla \cdot \mathbf{u}$. The scalar varies in space, so the product rule fires and we pick up the extra $\nabla f \cdot \mathbf{u}$ term. If we ever drop this term, dimensional check: the missing piece has units of (gradient)(field), exactly what the answer needs.
- Confusing div with curl. Div eats a vector and produces a scalar. Curl eats a vector and produces a vector. If we wrote three components for a divergence, we computed curl by accident.
- Mismatched indices. The formula is $\partial u_1/\partial x + \partial u_2/\partial y + \partial u_3/\partial z$ - first component differentiated with respect to first variable. Writing $\partial u_1/\partial y$ is the single most common arithmetic slip on this topic.
- Trying to take the divergence of a scalar. $\nabla \cdot f$ is meaningless - divergence needs a vector. What we probably want is $\nabla f$ (the gradient) or $\nabla^2 f$ (the Laplacian, which is $\nabla \cdot \nabla f$).
- Sign on the continuity equation. The accumulation form is $\partial \rho/\partial t = -\nabla \cdot (\rho \mathbf{u})$. The minus sign reflects: if mass flows out (positive divergence), density goes down. Drop the sign and we've reversed the physics.
- Treating $\mathbf{r} = (x,y,z)$ specially. It's just a vector field with all three diagonal partials equal to 1, so $\nabla \cdot \mathbf{r} = 3$ in space ($= 2$ in the plane). Worth memorizing - it shows up constantly in divergence-theorem problems.
Practice Problems - §3.4
From Kaplan, problems after §3.6
Prove the two basic properties of divergence: linearity over vector sums, and the product rule with a scalar.
Write $\mathbf{u} = (u_1, u_2, u_3)$ and $\mathbf{v} = (v_1, v_2, v_3)$. Then $\mathbf{u} + \mathbf{v} = (u_1 + v_1,\; u_2 + v_2,\; u_3 + v_3)$.
$\nabla \cdot (\mathbf{u} + \mathbf{v}) = \dfrac{\partial(u_1 + v_1)}{\partial x} + \dfrac{\partial(u_2 + v_2)}{\partial y} + \dfrac{\partial(u_3 + v_3)}{\partial z}$
$= \left(\dfrac{\partial u_1}{\partial x} + \dfrac{\partial u_2}{\partial y} + \dfrac{\partial u_3}{\partial z}\right) + \left(\dfrac{\partial v_1}{\partial x} + \dfrac{\partial v_2}{\partial y} + \dfrac{\partial v_3}{\partial z}\right) = \nabla \cdot \mathbf{u} + \nabla \cdot \mathbf{v}$ ✓
We just used the fact that partial differentiation is linear - the derivative of a sum is the sum of derivatives.
Now consider $f\mathbf{u} = (fu_1, fu_2, fu_3)$. Expand $\nabla \cdot (f\mathbf{u})$:
$\nabla \cdot (f\mathbf{u}) = \dfrac{\partial(fu_1)}{\partial x} + \dfrac{\partial(fu_2)}{\partial y} + \dfrac{\partial(fu_3)}{\partial z}$
Apply the single-variable product rule to each term:
$= \left(f\dfrac{\partial u_1}{\partial x} + u_1\dfrac{\partial f}{\partial x}\right) + \left(f\dfrac{\partial u_2}{\partial y} + u_2\dfrac{\partial f}{\partial y}\right) + \left(f\dfrac{\partial u_3}{\partial z} + u_3\dfrac{\partial f}{\partial z}\right)$
Group the $f$ terms and the $\nabla f$ terms:
$= f\left(\dfrac{\partial u_1}{\partial x} + \dfrac{\partial u_2}{\partial y} + \dfrac{\partial u_3}{\partial z}\right) + \left(\dfrac{\partial f}{\partial x}u_1 + \dfrac{\partial f}{\partial y}u_2 + \dfrac{\partial f}{\partial z}u_3\right)$
$= f\,(\nabla \cdot \mathbf{u}) + (\nabla f) \cdot \mathbf{u}$ ✓
Recognize the second group as a dot product: $\nabla f \cdot \mathbf{u}$. This is why we can't pull $f$ through the divergence - the product rule generates an extra term.
Starting from the continuity equation $\operatorname{div}(\rho\,\mathbf{u}) = -\dfrac{\partial \rho}{\partial t}$, show it can be written as $\dfrac{\partial \rho}{\partial t} + \nabla\rho \cdot \mathbf{u} + \rho\,\operatorname{div}\mathbf{u} = 0$, and deduce that $\operatorname{div}\mathbf{u} = 0$ when $\rho$ is constant.
From Problem 1, we proved $\nabla \cdot (f\,\mathbf{u}) = f\,(\nabla \cdot \mathbf{u}) + (\nabla f) \cdot \mathbf{u}$. Apply this with $f = \rho$:
$\operatorname{div}(\rho\,\mathbf{u}) = \rho\,\operatorname{div}\mathbf{u} + (\nabla\rho) \cdot \mathbf{u}$
The continuity equation says $\operatorname{div}(\rho\,\mathbf{u}) = -\dfrac{\partial\rho}{\partial t}$. Substituting:
$\rho\,\operatorname{div}\mathbf{u} + (\nabla\rho) \cdot \mathbf{u} = -\dfrac{\partial\rho}{\partial t}$
Rearranging:
$\dfrac{\partial\rho}{\partial t} + \nabla\rho \cdot \mathbf{u} + \rho\,\operatorname{div}\mathbf{u} = 0$ ✓
If $\rho$ is constant in both space and time, then:
- $\dfrac{\partial\rho}{\partial t} = 0$ (no change in time)
- $\nabla\rho = \mathbf{0}$ (no change in space)
The equation reduces to $\rho\,\operatorname{div}\mathbf{u} = 0$. Since $\rho \ne 0$, we get:
For an incompressible fluid, the velocity field must be divergence-free - no sources, no sinks. Every bit of fluid that enters a region must leave it.