Divergence measures the change in density of a fluid flowing according to a given vector field.

What we're building to

  • Interpret a vector field as representing a fluid flow.
  • The divergence is an operator, which takes in the vector-valued function defining this vector field, and outputs a scalar-valued function measuring the change in density of the fluid at each point.
  • This is the formula for divergence:
    divv=v=v1x+v2y+\begin{aligned} \quad \text{div}\, \vec{\textbf{v}} = \nabla \cdot \vec{\textbf{v}} = \dfrac{\partial \blueE{v_1}}{\partial \blueE{x}} + \dfrac{\partial \redE{v_2}}{\partial \redE{y}} + \cdots \end{aligned}
    Here, start color blueE, v, start subscript, 1, end subscript, end color blueE, start color redE, v, start subscript, 2, end subscript, end color redE, are the component functions of v, with, vector, on top.

Changing density in fluid flow

Take a look at the following vector field:
Notice, this particular drawing of the vector field is color-coded, in the sense you should interpret blue vectors as being shorter, and greenish-yellow vectors as being longer, even though technically they are all drawn with the same length.
So that's the picture, but what's the function?
v(x,y)=[2xyy2] \vec{\textbf{v}}(x, y) = \left[ \begin{array}{c} 2x - y \\ y^2 \end{array} \right]
The inputs to v, with, vector, on top are points in two-dimensional space, left parenthesis, x, comma, y, right parenthesis, and the outputs are two-dimensional vectors, which in the vector field are attached to the corresponding point left parenthesis, x, comma, y, right parenthesis.
A nice way to think about vector fields is to imagine the fluid flow they could represent. Specifically, for each point left parenthesis, x, comma, y, right parenthesis in two-dimensional space, imagine a particle sitting at left parenthesis, x, comma, y, right parenthesis flowing in the direction of the vector attached to that point, v, with, vector, on top, left parenthesis, x, comma, y, right parenthesis. Moreover, suppose the speed of the particle's movement is determined by the length of that vector. The following animation shows what this might look like for our given function v, with, vector, on top for just a brief instant:
Notice, during this fluid flow, some regions tend to become less dense with dots as particles flow away, such as the upper middle section. On the other hand, down and to the left of that region, particles tend to flow towards each other and the dots get more dense.
Key question: For a given vector-valued function v, with, vector, on top, left parenthesis, x, comma, y, right parenthesis, how can we measure the change in density of particles around a point left parenthesis, x, comma, y, right parenthesis as these particles flow along the vectors given by v, with, vector, on top, left parenthesis, x, comma, y, right parenthesis?
We can answer this question using a variation of the derivative called divergence. We'll talk more about fluid flow below, but first, let's establish the notation and formula used to express this concept.

Notation and formula for divergence

The notation for divergence uses the same symbol "del" which you may be familiar with from the gradient. As with the gradient, we think of this symbol loosely as representing a vector of partial derivative symbols.
=[xy]\begin{aligned} \quad \nabla = \left[ \begin{array}{c} \frac{\partial}{\partial x} \\ \\ \frac{\partial}{\partial y} \\ \\ \vdots \end{array} \right] \end{aligned}
We write the divergence of a vector-valued function like this
del, dot, v, with, vector, on top, space, left arrow, D, i, v, e, r, g, e, n, c, e, space, o, f, space, v, with, vector, on top
This is mildly nonsensical since del isn't really a vector. Its entries are operators, not numbers. Nevertheless, using this dot product notation is super helpful for remembering how to compute divergence, just take a look:
v=[xy][2xyy2]=x(2xy)+y(y2)=2+2y\begin{aligned} \quad \\ \nabla \cdot \vec{\textbf{v}} &= \left[ \begin{array}{c} \frac{\partial}{\partial x} \\ \\ \frac{\partial}{\partial y} \\ \end{array} \right] \cdot \left[ \begin{array}{c} 2x - y \\ y^2 \end{array} \right] \\ \\ &= \dfrac{\partial}{\partial \blueE{x}}(2\blueE{x}-y) + \dfrac{\partial}{\partial \redE{y}}(\redE{y}^2) \\ &= 2 + 2y \end{aligned}
More generally, the divergence can apply to vector-fields of any dimension. This means v, with, vector, on top can have any number of input variables, as long as its output has the same dimensions. Otherwise, it couldn't represent a vector field. If we write v, with, vector, on top component-wise like this:
Then the divergence of v, with, vector, on top looks like this:
v=[x1xn][v1vn]=v1x1++vnxn\begin{aligned} \quad \nabla \cdot \vec{\textbf{v}} = \left[ \begin{array}{c} \frac{\partial}{\partial x_1} \\ \vdots \\ \frac{\partial}{\partial x_n} \\ \end{array} \right] \cdot \left[ \begin{array}{c} v_1 \\ \vdots \\ v_n \\ \end{array} \right] = \dfrac{\partial v_1}{\partial x_1} + \cdots + \dfrac{\partial v_n}{\partial x_n} \end{aligned}
You could imagine taking the matrix of all possible partial derivatives (we could be fancy and call this the Jacobian), and adding all the diagonal elements:
[v1xv1yv1zv2xv2yv2zv3xv3yv3z]v1x+v2y+v3z\begin{aligned} \quad \left[ \begin{array}{ccc} \goldE{\dfrac{\partial v_1}{\partial x}} & \dfrac{\partial v_1}{\partial y} & \dfrac{\partial v_1}{\partial z} \\ \dfrac{\partial v_2}{\partial x} & \goldE{\dfrac{\partial v_2}{\partial y}} & \dfrac{\partial v_2}{\partial z} \\ \dfrac{\partial v_3}{\partial x} & \dfrac{\partial v_3}{\partial y} & \goldE{\dfrac{\partial v_3}{\partial z}} \\ \end{array} \right] \rightarrow \goldE{\dfrac{\partial v_1}{\partial x}} + \goldE{\dfrac{\partial v_2}{\partial y}} + \goldE{\dfrac{\partial v_3}{\partial z}} \end{aligned}
Let's summarize this with a quick diagram:

Interpretation of divergence

Let's say you evaluate the divergence of a function v, with, vector, on top at some point left parenthesis, x, start subscript, 0, end subscript, comma, y, start subscript, 0, end subscript, right parenthesis, and it comes out negative.
v(x0,y0)<0\begin{aligned} \quad \redE{\nabla \cdot \vec{\textbf{v}}(x_0, y_0) < 0} \end{aligned}
This means a fluid flowing along the vector field defined by v, with, vector, on top would tend to become more dense at the point left parenthesis, x, start subscript, 0, end subscript, comma, y, start subscript, 0, end subscript, right parenthesis. For example, the following animation shows a vector field with negative divergence at the origin.
On the other hand, if the divergence at a point left parenthesis, x, start subscript, 0, end subscript, comma, y, start subscript, 0, end subscript, right parenthesis is positive,
v(x0,y0)>0\begin{aligned} \quad \greenE{\nabla \cdot \vec{\textbf{v}}(x_0, y_0) > 0} \end{aligned}
the fluid flowing along the vector field becomes less dense around left parenthesis, x, start subscript, 0, end subscript, comma, y, start subscript, 0, end subscript, right parenthesis. Here's an example:
Finally, the concept of zero-divergence is very important in fluid dynamics and electrodynamics. It indicates that even though a fluid flows freely, its density stays constant. This is particularly handy when modeling incompressible fluids, such as water. In fact, the very idea that a fluid is incompressible can be tightly communicated with the following equation:
v=0\begin{aligned} \quad \blueE{\nabla \cdot \vec{\textbf{v}} = 0} \end{aligned}
Such vector fields are called "divergence-free." Here's an example of what that might look like:

Sources and sinks

Sometimes, for points with negative divergence, instead of thinking about a fluid getting more dense after a momentary fluid motion, some people imagine the fluid draining at that point while the fluid flows constantly. Here's what this might look like:
As such, points of negative divergence are often called "sinks."
Likewise, instead of thinking of points with positive divergence as becoming less dense during a momentary motion, these points might be thought of as "sources" constantly generating more fluid particles.

Divergence in higher dimensions

Although all the diagrams and animations I'm making show the two-dimensional case, you should understand that all these concepts could apply to three or more dimensions as well.
Try this as a good mental exercise to test if you understand what divergence represents: Imagine a three-dimensional vector field, and picture what points of positive, negative, and zero divergences might look like.

Example 1: Compute and interpret divergence

Vector field for Example 1
Problem: Define a vector field by
v(x,y)=(x2y2)i^+2xyj^\begin{aligned} \quad \vec{\textbf{v}}(x, y) = (x^2 - y^2)\hat{\textbf{i}} + 2xy\hat{\textbf{j}} \end{aligned}
Compute the divergence, and determine whether the point left parenthesis, 1, comma, 2, right parenthesis is more of a source or a sink.
Step 1: Compute the divergence.
del, dot, v, with, vector, on top, equals

We compute divergence by applying the formula. Add the partial derivative with respect to x of the first component to the partial derivative with respect to y to the second component.
Step 2: Plug in left parenthesis, 1, comma, 2, right parenthesis.
del, dot, v, with, vector, on top, left parenthesis, 1, comma, 2, right parenthesis, equals

Evaluating this function at the point left parenthesis, 1, comma, 2, right parenthesis, we get
v(1,2)=4(1)=4\begin{aligned} \quad \nabla \cdot \vec{\textbf{v}}(1, 2) = 4(1) = 4 \end{aligned}
Step 3: Interpret. Is the fluid more of a source or a sink at left parenthesis, 1, comma, 2, right parenthesis?
Choose 1 answer:
Choose 1 answer:

Because this is positive, the density of a fluid flowing along the vector field given by v, with, vector, on top, left parenthesis, x, comma, y, right parenthesis decreases at the point left parenthesis, 1, comma, 2, right parenthesis. Therefore, it is more of a source.

Confusing signs

It always trips me up that positive divergence indicates a negative change in density, and that a negative divergence indicates a positive change in density. Isn't that confusing? The sources/sinks interpretation helps a bit, because points of positive divergences are generating more fluid, while points of negative divergence are sucking it away.
Personally, the way I always remember is to think of the case when f is the identity function, taking the point left parenthesis, x, comma, y, right parenthesis to the vector [xy]\left[\begin{array}{c} x \\ y \end{array} \right]. The resulting vector field has all vectors pointing away from the origin (can you see why?), and it's relatively quick to compute del, dot, f.
f=x(x)+y(y)=1+1=2\begin{aligned} \quad \nabla \cdot f = \dfrac{\partial}{\partial \blueE{x}}(\blueE{x}) + \dfrac{\partial}{\partial \redE{y}}(\redE{y}) = \blueE{1} + \redE{1} = 2 \end{aligned}
So each time I return to divergence after not having seen it for a while and think "hmm, is it positive or negative divergence that indicates a loss in density," I go through this little exercise and remember, "Ah yes, that's how it goes, positive divergence indicates an outward flow."

Further resources

In the next article, I'll give an intuition for why the formula for divergence has anything to do with fluid flow.
Later on, once line integrals and surface integrals are covered, I talk about the formal definition of divergence.

Summary

  • Interpret a vector field as representing a fluid flow.
  • The divergence is an operator, which takes in the vector-valued function defining this vector field, and outputs a scalar-valued function measuring the change in density of the fluid at each point.
  • The formula for divergence is
    divv=v=v1x+v2y+\begin{aligned} \quad \text{div}\, \vec{\textbf{v}} = \nabla \cdot \vec{\textbf{v}} = \dfrac{\partial \blueE{v_1}}{\partial \blueE{x}} + \dfrac{\partial \redE{v_2}}{\partial \redE{y}} + \cdots \end{aligned}
    where start color blueE, v, start subscript, 1, end subscript, end color blueE, start color redE, v, start subscript, 2, end subscript, end color redE, are the component functions of v, with, vector, on top.
Keep in mind, though, divergence is used in all sorts of contexts which can have nothing to do with fluid. Electrodynamics is a big one, for example. The fluid flow interpretation is very useful, and gives a much stronger intuition than a blind use of symbols would, but it should be taken with a grain of salt from time to time.