If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Divergence

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+
    Here, v1, v2, are the component functions of v.

Changing density in fluid flow

Take a look at the following vector field:
So that's the picture, but what's the function?
v(x,y)=[2xyy2]
The inputs to v are points in two-dimensional space, (x,y), and the outputs are two-dimensional vectors, which in the vector field are attached to the corresponding point (x,y).
A nice way to think about vector fields is to imagine the fluid flow they could represent. Specifically, for each point (x,y) in two-dimensional space, imagine a particle sitting at (x,y) flowing in the direction of the vector attached to that point, v(x,y). 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 for just a brief instant:
Khan Academy video wrapper
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(x,y), how can we measure the change in density of particles around a point (x,y) as these particles flow along the vectors given by v(x,y)?
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 "" 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]
We write the divergence of a vector-valued function v(x,y,) like this
vDivergence of v
This is mildly nonsensical since 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
More generally, the divergence can apply to vector-fields of any dimension. This means v 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 component-wise like this:
v(x1,,xn)=[v1(x1,,xn)vn(x1,,xn)]
Then the divergence of v looks like this:
v=[x1xn][v1vn]=v1x1++vnxn
Let's summarize this with a quick diagram:

Interpretation of divergence

Let's say you evaluate the divergence of a function v at some point (x0,y0), and it comes out negative.
v(x0,y0)<0
This means a fluid flowing along the vector field defined by v would tend to become more dense at the point (x0,y0). For example, the following animation shows a vector field with negative divergence at the origin.
Khan Academy video wrapper
On the other hand, if the divergence at a point (x0,y0) is positive,
v(x0,y0)>0
the fluid flowing along the vector field becomes less dense around (x0,y0). Here's an example:
Khan Academy video wrapper
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
Such vector fields are called "divergence-free." Here's an example of what that might look like:
Khan Academy video wrapper

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:
Khan Academy video wrapper
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.
Khan Academy video wrapper

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^
Compute the divergence, and determine whether the point (1,2) is more of a source or a sink.
Step 1: Compute the divergence.
v=

Step 2: Plug in (1,2).
v(1,2)=

Step 3: Interpret. Is the fluid more of a source or a sink at (1,2)?
Choose 1 answer:

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 (x,y) to the vector [xy]. The resulting vector field has all vectors pointing away from the origin (can you see why?), and it's relatively quick to compute f.
f=x(x)+y(y)=1+1=2
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+
    where v1, v2, are the component functions of v.
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.

Want to join the conversation?

  • starky ultimate style avatar for user Chiarandini Pandetta
    Will there be exercises for multivariable calculus in the future?
    (51 votes)
    Default Khan Academy avatar avatar for user
    • mr pants teal style avatar for user Arman Rafian
      I'm almost sure that KA's goal is to develop practice and then mastery exercises for every subject, but since it is a work in progress, they are probably focusing on what they feel is most important at the moment. I'm guessing that the majority of users on KA are not here for more advanced math like this course, so they may be trying to focus on other subjects, or lower level math. For example this July/August they are coming out with quite a few more exercises here all the way up to BC Calculus. You can find this here:
      https://khanacademy.zendesk.com/hc/en-us/articles/115007408888

      It seems in the past six months the team has been working more on statistics, history, and more tools for teachers/coaches. It must be a tough task to try to work on so many things at once, but hopefully they can get some exercises for this stuff in the next few years as well!
      (22 votes)
  • leaf orange style avatar for user Connor Doherty
    Why not just call the negative of divergence the "convergence" and eliminate all confusion? You can look at a source or sink and instantly tell if the particles are converging, coming toward each other. Faster than telling if they are doing the opposite of that, and eliminates confusion (converge = high density).
    (17 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user Oleg Novikov
      On the contrary, it will be more confusing.

      Example 1. Consider the inverse of what the author uses as a reminder, the function which takes the point (x, y) to the vector (-x,-y):

      f(x,y)=-xi-yj

      The resulting vector field has all vectors pointing to the origin, the divergence is negative and equals to -2. In this case the divergence is negative at any point of the field but intuitively you think about it as coverging only at the origin.

      Example 2. Consider the function which takes the point (x, y) to the vector (-exp(x), 0):

      f(x,y)=-exp(x)i

      The resulting vector field has all vectors pointing horisontally to the left since theres no y component and the divergence is again strictly negative at any point. Nevertheless this flow never converges anywhere (except maybe when x equals minus infinity).
      (12 votes)
  • leaf green style avatar for user Alexander Wu
    Technically operators are functions. When I first learned about them, functions are anything that takes in something and outputs an unambiguous something else. For example, there was f(Paul) = Mary or something like that. So functions probably can also input and output other functions. Therefore, divergence is a function that inputs and outputs functions that input and output vectors and scalars, respectively.

    Right......?
    (2 votes)
    Default Khan Academy avatar avatar for user
    • leaf orange style avatar for user Connor Doherty
      Not quite. Operators are more fundamental... The plus sign "+" is an operator, for example, although it is "infix", meaning the first argument/parameter goes in front of it rather than after. If it wasn't infix, x+y would look something like this: +(x,y) or more clearly, sum(x,y). Likewise with multiply(x,y) and subtract(x, y), etc. Other operators are not infix, such as derivative(x) or grad(x), written with their respective symbols. But how would you define these "functions" with only other symbols, without explaining their abstract concepts?

      I mean, some function f(x) could be defined as f(x)=3+x. Simple. g(y) = 4/y. and so on. But notice how I had to use those fundamental operators to define them? (+ and /)

      Yet those operators can't be written in such a way. What's the definition of sum(x,y)? "You just gotta add them". F(x) might be equal to 1, and derivative(x) also. But can you write out a function f( ) that always puts out exactly what derivative( ) puts out? Try it.

      Something that "takes something in and outputs something else" is not specific enough to define functions, nor operators, for this reason. You will see that they are not the same thing. You can describe a function in terms of operators ("this function adds three to its input"), but you can't describe those operators without more operators ("what do you mean, 'adds'? What is this 'addition' you speak of?")

      You could think of operators as "verbs". They're like "actions" you can take on some function/expression that keeps it a function/expression. Like, "take the derivative". That's a verb that does things to functions, not just variables and constants.

      Sure, you can define a function like f(x) in terms of another, such as f(x) = g(x) +3, where g(x) is x+2. But for x=7 you'd first evaluate g(7)=9 and pass it into f(7)=9+3=12, whereas you cannot do that with deriv( m(x) ) where m(x) = x^2, because passing the constant (7)^2=49 into deriv(49) gets you zero, when you should have passed the x^2 as it is, getting you deriv(x^2) = 2x, which you can then evaluate to get 14. Operators cannot be "evaluated" at a value like functions, they fundamentally change the function (x^2 --> 2x) and must always be done first (highest precedence, so before anything else in PEMDAS) so are called left-associative instead of right-associative (done from the outside in. instead of instead out). So in F(deriv(x(y(t)))+2), that derivative must be done before its insides (x,y...) and even before it can be passed to the function outside (F) that contains it. It's kind of like the difference between "pass by reference" and "pass by value" in computer science. You work directly on the input function itself ("reference") rather than it's output ("value").
      (22 votes)
  • duskpin seedling style avatar for user Dinghao Luo
    I would suggest remembering the sign-divergence stuff just by understanding that the word 'divergence' means 'the quality of going out from a single point,' and when there is a positive divergence, that means there IS divergence, whilst when there is a negative one, that means there IS a sort of 'anti-divergence.'
    (5 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Andres
    The "quick diagram" is so tiny that it's practically impossible to see...
    (3 votes)
    Default Khan Academy avatar avatar for user
  • starky tree style avatar for user scourge
    why don't we use the y coordinate in the first partial derivative, and the x coordinate in the second partial derivative for the divergence?
    (2 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user senthilkumar
    what is the difference between divergence and gradient? are they same
    (2 votes)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user Adit Stegosaurous
      The gradient of a function is a vector that consists of all its partial derivatives.

      For example, take the function f(x,y) = 2xy + 3x^2. The partial derivative with respect to x for this function is 2y+6x and the partial derivative with respect to y is 2x. Thus, the gradient vector is equal to <2y+6x, 2x>. Divergence, on the other hand, is described above in the article and can be thought of as the dot product between a vector of partial derivatives and the vector function that determines the vector field. Hope this helps!
      (1 vote)
  • blobby green style avatar for user Gregory
    Hi, I would like to know if I have the function
    vf(x,y) = [xy, y^2], why it is being done just by two partial derivatives like:
    [y,2y] but not it this way [[y,x],[2y,0]]
    (1 vote)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user MBCory
      You do not get a 2x2 matrix of derivatives (called the Jacobian, and referenced in this article), because you are not taking all possible derivatives when calculating divergence. You just take d/dx(vsubx) + d/dy(vsuby), where vsubx is the function that is the x-component of v and vsuby is the y-component of v. Hope this helps!
      (3 votes)
  • orange juice squid orange style avatar for user apndolby297
    Is it correct to say that on simple addition of the terms of gradient ,we obtain the divergence?

    And also why is it that the summation of these terms determines why the fluid is getting collected or distributed...?
    *The summation in itself doesn't appear to be something so significant in terms of first impressions..*
    (1 vote)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user MBCory
      To answer your first question, it is not quite accurate to say that we are adding the terms of the gradient, because the gradient is only defined for functions that output scalar values, and divergence is defined for vector-valued functions.
      (2 votes)
  • blobby green style avatar for user Michaelson Britt
    Looking at the Incompressible Fluid Flow Example; it appears that both the X and Y coordinate values of the vectors change while moving from left-to-right through any point on the graph, yet neither the X or Y coordinates change while moving from bottom-to-top through any point on the graph. That seems to imply that the partial derivative of the first vector coordinate v1 with respect to x is nonzero, while the partial derivative of of the second vector coordinate v2 with respect to y remains zero. The divergence is defined as the sum of these two partial derivative scalars (is that correct?). Adding the two scalars yields a nonzero scalar everywhere on the graph, thus the divergence would be nonzero everywhere, indicating some divergence or convergence (compressibility). This must reflect an incorrect understanding of divergence, as the example is for incompressibilty. How is this incorrect?
    (1 vote)
    Default Khan Academy avatar avatar for user
    • ohnoes default style avatar for user Charles Morelli
      I'm afraid i found your question confusing, but i think i understand your point now.
      First of all, whilst accepting that a vector field is very helpful as a visualisation, IMHO functions should generally be considered to output into their own space, so your use of x and y 'coordinates' for the output vector confused me (you later refer to them as v1 and v2 'coordinates', i think).
      I will use '1st' and '2nd' components of the output vector (and functions v1(x,y) and v2(x,y) respectively for those entities), and the 'x' and 'y' coordinates of the input to avoid confusion of terminology.
      I understand your point suggests that the 1st and 2nd components (‘v1’ and ‘v2’) of the output vector both seem to change continuously as you look from left to right (i.e., as the x-input coordinate increases) across the input space implying ∂v1(x,y)/∂x ≠ 0 (also ∂v2(x,y)/∂x ≠ 0, but that is irrelevant to the answer)
      [whereas: i think the 1st ('v1') component of the output vector is, in fact, constant across the whole x-y plane as i discuss shortly];
      also, that both output components appear constant as only the y-input changes (∂v2(x,y)/∂y = 0; also ∂v1(x,y)/∂y = 0, but again, the latter is irrelevant to the answer).
      I think the main issue here is that the unanimated vector arrows are all the same length and there is no colour-coding to indicate variation in magnitude. I don't think the arrows really have the same magnitude, but that this is a simplification for visualisation purposes.
      [I thought Grant had given the function behind that animation somewhere but i can't find it now, so can’t confirm the maths, so this is what i think is going on]
      1) the arrows only indicate vector direction, there is no magnitude information given (and magnitude here is NOT constant if my other suppositions are correct: i.e., vectors with a vertical component should have greater magnitude than those without);
      2) there is no change to the 1st component of the output vector as the x-input changes, but the 2nd output component varies with x
      (i.e.,: ∂v/∂x = (0)î + (∂v2(x,y)/∂x)ĵ - using another notation format)…
      so i think if you track the dots moving from left to right in the animation and ignore the vertical oscillation, you see that they move at a constant horizontal velocity;
      3) there is no change to the output vector at all as only the y-input varies
      (i.e: ∂v/∂y = (0)î + (0)ĵ ).
      In summary, ∂v1(x,y)/∂x = 0 and ∂v2(x,y)/∂y = 0 hence their sum is also 0, hence zero divergence.
      (1 vote)