---
title: "Divergence: sources and sinks"
heading: Measuring how much a field spreads out from a point
eyebrow: A9 · Lesson 33 · Divergence
xp: 40
---

::: hook
Where does an electric field come from? From charges: field lines spring out of positive charge and pour into negative charge. Put a tiny imaginary bubble anywhere and count the flux leaving it. If more leaves than enters, there's a source inside. Shrink the bubble to a point and that count, per unit of size, becomes a number at every point of space: the divergence. Gauss's law says the divergence of the electric field is the charge density.

::: play
- The field is $\mathbf{F} = (x^3/3 - x,\ y/2)$. The circle is a flux meter centered at $(x_0, y_0)$ with radius $r$. The readout divides the flux out of it by its area.
- Move the meter around. Where is the result positive, and where negative? Look at the arrows near each spot.
- Shrink $r$. What number does the meter's reading settle toward? Compare it with the other readout.
:::
:::

```sim plot
view: flow
x: x = -2.5..2.5
y: y = -2..2
slider: x0 = -2..2 step 0.1 = 1.5
slider: y0 = -1.5..1.5 step 0.1 = 0
slider: r = 0.05..1 step 0.05 = 0.6
dx: x^3/3 - x
dy: y/2
arrows: scaled
grid: 14
shade: x^2 - 0.5 | contours: 0 | scale: 4
path: x0 + r*cos(u), y0 + r*sin(u) | over: u = 0..2*pi | flux: P | label: meter
readout: flux out ÷ area = P/(pi*r^2)
readout: ∇·F at center = x0^2 - 0.5
```

::: predict
## At $(0, 0)$ the arrows along $x$ point inward from both sides, and along $y$ they point outward, more gently. Is the divergence there positive or negative?

- [ ] Positive
- [x] Negative
- [ ] Zero
- [ ] It isn't defined there

::: reveal
Negative. Along $x$ the field pours in at a rate of 1 per meter ($\partial F_x/\partial x = x^2 - 1 = -1$ at the center), while along $y$ it spreads out at only 0.5. The net is $-0.5$: a sink. The shading shows the divergence everywhere: one color where the field is spreading out, the other where it's converging.
:::
:::

::: nameit
## Divergence

The **divergence** of a field at a point is the net flux out of a tiny region around it, per unit of the region's size (area in 2D, volume in 3D), in the limit as the region shrinks:

$$\nabla \cdot \mathbf{F} = \lim_{V \to 0}\frac{1}{V}\oint_S \mathbf{F} \cdot d\mathbf{A}$$

**Computing it.** For a small box, the flux out through the two faces square to $x$ differs by about $\frac{\partial F_x}{\partial x}\Delta x$ times their area, and the same for $y$ and $z$. So:

$$\nabla \cdot \mathbf{F} = \frac{\partial F_x}{\partial x} + \frac{\partial F_y}{\partial y} + \frac{\partial F_z}{\partial z}$$

The notation reads like a dot product of $\nabla = (\partial_x, \partial_y, \partial_z)$ with $\mathbf{F}$. Each term asks: is this part of the field getting bigger as you move in its own direction? If so, more leaves than enters along that axis.

**Reading it:**

| $\nabla \cdot \mathbf{F}$ | Meaning | Example |
|---|---|---|
| positive | a source: field lines start here | $\mathbf{E}$ where there's positive charge |
| negative | a sink: field lines end here | $\mathbf{E}$ where there's negative charge |
| zero | whatever flows in flows out | $\mathbf{B}$, everywhere |

A field can have zero divergence and still look busy: the rotation $(-y, x)$ has $\nabla \cdot \mathbf{F} = 0 + 0$, since its lines go around and never start or stop.

**The laws in this language.**

- Gauss's law: $\nabla \cdot \mathbf{E} = \rho/\varepsilon_0$. Charge density is the source of electric field, with $\varepsilon_0 = 8.854 \times 10^{-12}$ F/m.
- No magnetic charges: $\nabla \cdot \mathbf{B} = 0$.
- Charge is conserved: $\nabla \cdot \mathbf{J} = -\partial\rho/\partial t$. Where current spreads out from a point, the charge there must be draining away. In a circuit at steady state, $\nabla \cdot \mathbf{J} = 0$, which is Kirchhoff's current law: what flows into a node flows out.
:::

::: example
## Find the divergence of $\mathbf{F} = (x^2, xy)$ at $(2, 1)$.

::: solution
1. **Add the partials.**
   $$\begin{aligned} \nabla\cdot\mathbf{F} &= \frac{\partial}{\partial x}x^2 + \frac{\partial}{\partial y}xy \\ &= 2x + x \\ &= 3x \end{aligned}$$
2. **Evaluate at $(2, 1)$.** It's 6: a source, with more leaving each small box than entering.

**Answer:** the divergence at $(2, 1)$ is 6.
:::
:::

::: example
## Find the divergence of the rotation $\mathbf{F} = (-y, x)$.

::: solution
1. **Add the partials.**
   $$\begin{aligned} \nabla\cdot\mathbf{F} &= \frac{\partial(-y)}{\partial x} + \frac{\partial x}{\partial y} \\ &= 0 + 0 \\ &= 0 \end{aligned}$$
2. **Interpret.** A pure rotation neither creates nor destroys flow: whatever enters a small box leaves it.

**Answer:** the divergence is 0 everywhere.
:::
:::

::: example
## Find the divergence of $\mathbf{F} = (x^3, y^3, z^3)$ at $(1, 1, 2)$.

::: solution
1. **Add the partials.**
   $$\begin{aligned} \nabla\cdot\mathbf{F} &= 3x^2 + 3y^2 + 3z^2 \\ &= 3 + 3 + 12 \\ &= 18 \end{aligned}$$
2. **Interpret.** It's positive everywhere except the origin: the field spreads out from every point, faster farther away.
3. **Compare a point charge.** Its field, $\frac{\hat{\mathbf{r}}}{r^2}$, has zero divergence everywhere except at the charge itself, which is why Gauss's law gives the same flux through every sphere around it.

**Answer:** the divergence at $(1, 1, 2)$ is 18.
:::
:::

::: check
given: a = 1..9 int; b = -9..-1 int
answer: a + b
tolerance: 0.001

## What is the divergence of $\mathbf{F} = (\given{a}x,\ \given{b}y)$?

::: right
Right. $\partial(\given{a}x)/\partial x + \partial(\given{b}y)/\partial y = \given{a} + (\given{b})$ = {answer}.
:::

::: misses
- [a - b] Add the two partial derivatives, keeping b's sign.
- [a*b] Divergence adds the partial derivatives.
- [any] Not yet. $\nabla \cdot \mathbf{F} = \partial F_x/\partial x + \partial F_y/\partial y$.
:::
:::

::: check
given: a = 2 | 4; b = 1 | 3; x0 = 1 | 3; y0 = -3 | -1 | 4
answer: 2*a*x0 + 2*b*y0
tolerance: 0.5%

## Find $\nabla \cdot \mathbf{F}$ at $(\given{x0}, \given{y0})$ for $\mathbf{F} = (\given{a}x^2,\ \given{b}y^2)$.

::: right
Right. $2\cdot\given{a}x + 2\cdot\given{b}y$ = {answer} there.
:::

::: misses
- [a*x0^2 + b*y0^2] That's adding the parts of F. Differentiate each one first.
- [2*a*y0 + 2*b*x0] Differentiate $F_x$ with respect to x and $F_y$ with respect to y.
- [any] Not yet. $\partial F_x/\partial x + \partial F_y/\partial y$, then put in the point.
:::
:::

::: check
given: D = 1..9 int; p = 3 | 6 | 9
answer: 8.854e-12*D*10^p
unit: C/m^3
tolerance: 1%

## In some region the electric field has $\nabla \cdot \mathbf{E} = \given{D} \times 10^{\given{p}}$ V/m². What is the charge density there?

::: right
Right. $\rho = \varepsilon_0\,\nabla \cdot \mathbf{E}$ = {answer}.
:::

::: misses
- [D*10^p/8.854e-12] Multiply by $\varepsilon_0$: Gauss's law is $\nabla \cdot \mathbf{E} = \rho/\varepsilon_0$.
- [D*10^p] Include $\varepsilon_0 = 8.854 \times 10^{-12}$ F/m.
- [any] Not yet. $\rho = \varepsilon_0\nabla \cdot \mathbf{E}$.
:::
:::

::: check
given: d = 2..9 int; s = 1 | 2 | 5
answer: d*(s/1000)^3
tolerance: 1%

## The divergence of a field is {d} (per meter) throughout a small cube {s} mm on a side. Roughly what net flux leaves the cube?

::: right
Right. Net flux out ≈ divergence × volume = {answer}.
:::

::: misses
- [d*(s/1000)^2] Divergence is per unit volume: multiply by the cube's volume, not a face's area.
- [d*s^3] Convert millimeters to meters.
- [any] Not yet. Flux out ≈ $(\nabla \cdot \mathbf{F})\,V$.
:::
:::

::: check
kind: choice

## What does $\nabla \cdot \mathbf{B} = 0$ say about magnetic fields?

- [ ] Magnetic fields are always zero inside conductors
- [x] There are no magnetic charges: field lines never start or end
- [ ] Magnetic fields don't change in time
- [ ] Magnetic fields can't do work

::: right
Right. Nothing is a source or sink of B, so every line that enters a region also leaves it.
:::

::: misses
- [1] It's a statement about every point in space, not just conductors.
- [3] It says nothing about time.
- [4] That's true of the magnetic force on a moving charge, but it's a different statement.
:::
:::

::: check
kind: parts
given: x = 1 | 2; y = 1 | 3; z = 2 | 3

## Find the divergence of $\mathbf{F} = (x^3, y^3, z^3)$ at $(\given{x}, \given{y}, \given{z})$.

::: part
answer: 3*(x^2 + y^2 + z^2)
tolerance: 0.5%

### What is it?

::: misses
- [x^2 + y^2 + z^2] Each derivative brings a factor 3.
- [any] $3x^2 + 3y^2 + 3z^2$.
:::
:::
:::

::: check
kind: derivation
vars: x = 0.5..2, y = 0.5..2, z = 0.5..2

## The point-charge field $\mathbf{F} = \frac{(x, y, z)}{r^3}$ has $\frac{\partial F_x}{\partial x} = \frac{1}{r^3} - \frac{3x^2}{r^5}$.

::: step
answer: 3/(x^2 + y^2 + z^2)^1.5

### What is $\frac{1}{r^3}$ summed over the three components, $\frac{3}{r^3}$?
:::

::: step
answer: 3/(x^2 + y^2 + z^2)^1.5

### What is $\frac{3(x^2 + y^2 + z^2)}{r^5}$?
:::

::: right
Right. The two parts are equal, so the divergence is zero away from the charge.
:::
:::

::: explain
## Why does a positive divergence at a point mean a source of field is there?

::: model
Divergence measures the net flux leaving a tiny region around the point, per unit volume. If it's positive, more field comes out of the region than goes in, so something inside must be producing it. For the electric field that something is positive charge: Gauss's law says the divergence equals the charge density divided by $\varepsilon_0$, so field lines begin where there's positive charge.
:::
:::

::: practice

::: check
given: a = 1..5 int; b = 1..5 int
answer: 0
tolerance: 0.001

## What is the divergence of $\mathbf{F} = (\given{a}x + \given{b}y,\ \given{b}x - \given{a}y)$?

::: misses
- [2*a] The y part contributes $\partial(-\given{a}y)/\partial y = -\given{a}$.
- [any] Add $\partial F_x/\partial x$ and $\partial F_y/\partial y$.
:::
:::

::: check
given: k = 1..9 int
answer: 3*k
tolerance: 0.5%

## What is the divergence of the 3D field $\mathbf{F} = \given{k}(x, y, z)$?

::: misses
- [k] Each of the three directions contributes {k}.
- [2*k] There are three terms in 3D.
- [any] $\partial F_x/\partial x + \partial F_y/\partial y + \partial F_z/\partial z$.
:::
:::

::: check
given: a = 2..5 int; x0 = 2 | 4
answer: 3*a*x0^2
tolerance: 0.5%

## What is the divergence of $\mathbf{F} = (\given{a}x^3,\ 0)$ at $x$ = {x0}?

::: misses
- [a*x0^3] That's $F_x$. Differentiate it.
- [3*a*x0] $\frac{d}{dx}x^3 = 3x^2$.
- [any] $\partial F_x/\partial x = 3\given{a}x^2$.
:::
:::
:::
