Main content

# Divergence formula, part 2

Here we finish the line of reasoning which leads to the formula for divergence in two dimensions. Created by Grant Sanderson.

## Want to join the conversation?

- Since the i component in the vector V (P(x,y)) clearly from its notation depends on both x and y, why one get its partial derivative with respect to x?(32 votes)
- Firstly I think this is a fantastic question as it seems rather unintuitive, maybe even arbitrary, that you take the partial of P with respect to only one of its variables - it seems like we are leaving out information about how the P component changes with respect to our other variable.

The way I have rationalized it is as follows, and it relies on the understanding that we are working with**vector valued functions**(meaning we are getting a vector from this function): P(x,y) represents the contribution of the vector in the x direction. That is all it is. Sure, maybe it has a bunch of y terms in it. In fact, it could be P(x,y) = y^2 (and thus ∂P/∂x will be 0) [here I will assume**V(x,y)* = (P(x,y), 0 )]. But all you and I care about is how this *x-component**changes in the**x-direction**. That is critical to us to understand if there is any**divergence**related to the x-component.

Importantly, think about what it would mean if we took ∂P/∂y and found 2y. This means along the vertical, every time we go up one notch, the length of the vector is twice as long as the one before it.**But what information does this tell us about the divergence**. As I see it, it tells us nothing valuable, but it may help to examine a few different scenarios. So, if I am at y = 1 and the vector is length 2 in the x direction, and then at y = 2 the vector length is 4, this doesn't tell me if the vectors around these points are expanding or contracting. In all of these cases, along the line y=1, y=2, these vector lengths**could be constant, thereby, having a divergence of 0 or they could vary wildly, and have a divergence that approaches infinity**In fact, in the case of**V**= (P(x,y), 0 ), the divergence is 0. And so while I might calculate a positive ∂P/∂y,**knowing how the x-component changes with respect to the "y" component does not give me information about the divergence**, as we have seen above, regardless of ∂P/∂y, both a divergence of 0 or infinity/-infinity are possible, and thus this isn't terribly useful for trying to figure out if our function diverges.(44 votes)

- Intuitively speaking, if the partial derivative of Q(x,y) with respect to y is negative, shouldn't that lead to divergence as well? That corresponds, if I understand it correctly, to a "negative increase" of the y component, that is, the y component gets larger in magnitude downwards. So if we imagine a fluid flowing in that point, it flows more and more away from the point, no matter if the partial derivative is positive or negative?(7 votes)
- Oh yes, I love this question because I got tricked too at first.

Here's my humble opinion: say if the partial of**q**in respect to**y**is**positive**at point**s**, an**increase**of y will make q more**positive**(pointing away from s) and a**decrease**of y will make q more**negative**(pointing away from s).

In contrast, if the derivative is**negative**, an**increase**of y will make q, here is the catch, more**negative**(pointing towards s) and a**decrease**of a y will make q more**positive**(also pointing towards s as well)!

Therefore, if the derivative is negative at a point, things**converge**towards it.(6 votes)

- Hi every one,

Why the formula just accounts for partial derivative with respect to one component? for example we can compute the partial derivative of p(x,y) with respect to y too, as the y is changing the output first component i.e p too.(4 votes)- But that doesn't really give us information on the divergence. Imagine for a second that you had a vector valued function whose y component was 0 (i.e. horizontal vectors). What if as your y input increased, the x component got larger (i.e. dP/dy > 0)? That would mean the particles at higher levels of y are moving to the right faster (or to the left slower) than the particles below them. But, this doesn't tell us anything about the divergence! So in this case, we don't really care about dP/dy for divergence. Similar arguments can be made in other scenarios.(6 votes)

- Is there a possibility that the vector v has 3 inputs P(x,y), Q(x,y) and R(x,y)? If that is possible, what would be the div function?(1 vote)
- This does work for a three-dimensional vector field, but each of your component functions P, Q and R would have to take in 3 inputs (since the input would then be a point in three-dimensional space), so they would look like P(x, y, z), Q(x, y, z) and R(x, y, z).(7 votes)

- Still don't understand why there is no dP/dy component in the divergence formula. Do P and x need to be aligned in some sense? Could someone explain? Thanks.(3 votes)
- In the formula for divergence, what does the value we get (dP/dx + dQ/dy) represent? e.g What does it mean if we get a "divergence of 1?"(3 votes)
- This is the same thing as using the gradient operator dot product on a vector function(2 votes)
- Is this a case of divergence too? ----> <-- ------->(2 votes)
- Since we are interested in how the vector will change as x and y changes, why do we not consider dP/dy and dQ/dx. Isn't y also going to change the value of P as it changes? In other words, why do we only consider dP/dx and dQ/dy, not including dP/dy and dQ/dx?(2 votes)
- Wouldn't it make more sense for the div to be equal to the square root of the sum of the squares? Why is it not this way?(2 votes)

## Video transcript

- [Voiceover] Hello
again, in the last video we were looking at vector fields that only have an X component, basically meaning all of the vectors point just purely to the
left or to the right, with nothing up and down going on. Then we landed at the idea that the divergence of V, you know when you take the divergence of
this vector valued function, it should definitely have something to do with the partial derivative of P, that X component of the output, with respect to X, and here I wanna do the opposite, and say, okay, what if
we look at functions where that P, that
first component is zero, but then we have some kind
of positive Q component, some kind of positive,
well maybe not positive, but some kind of non-zero, so positive or negative Y component, and what this would mean, instead of thinking about
vector as just left and right, now we're looking at vectors that are purely up or down, kind of up or down. So kind of doing the same
thing we did last time, if we start thinking about cases where the divergence of our function at a given point should be positive, and an example of that,
you might be saying, nothing is happening at the point itself, so Q itself would be
zero but then below it, things are kind of going away so they're pointing down, and above it, things are going up. So in this case down here, Q is a little bit less than zero, the Y component of that
vector is less than zero, and up here, Q is greater than zero. So here we have the idea
that as you're going from the bottom up, the Y value of your input is increasing as you're moving upward in space, the value of Q, this Y
component of the output, should also be increasing because it goes from negative to zero to positive. So now you're starting to get this idea of partial Q with respect to Y, you know, as we change that
Y and move up in space, the value of Q should be positive, so positive divergence seems to correspond to a positive value here. And the thinking is actually gonna be almost identical to what we did in the last video with the X component, because you can think
of another circumstance where maybe you actually have a vector attached to your point
and something's going on, and there even is some
convergence towards it, where you have some fluid flow in towards the point, but it's just heavily outweighed by even higher divergence, even higher flow away from your point above it, and again you have this idea of Q starts off small, so here's kind of, Q starts off small, maybe
it's kind of like near zero, and then here Q is something positive and then here it's even more positive, and sort of making up notation here but I want the idea of kind of small and then medium-sized and then bigger, and once again, the idea
of partial derivative of Q with respect to Y being greater than zero seems to correspond to
positive divergence, and if you want, you can sketch out many more circumstances and think about what if the vector
started off pointing down, what would positive and negative and zero divergence all look like, but the upshot of it all, pretty much for the same reasons I went
through in the last video, is this partial derivative
with respect to Y corresponds to the divergence. And when we combine this with our conclusions about the X component, that actually is all you need
to know for the divergence. So just to write it all out, if we have a vector valued
function of X and Y, and it's got both of its components, we've got P as the X
component of the output, that first component of the output, and Q, and we're looking
at both of these at once, the way that we compute divergence, the definition of divergence
of this vector valued function, is to say divergence of V as a function of X and Y, is actually equal to the
partial derivative of P with respect to X, plus, the partial derivative
of Q with respect to Y. And that's it, that is the
formula for divergence, and hopefully by now,
this isn't just kind of a formula that I'm plopping down for you, but it's something that
makes intuitive sense, when you see this term, this partial P with respect to X, you're thinking about, oh yes, yes, because if you have flow that's kind of increasing as you move in the X direction, that's gonna correspond
with movement away, and this partial derivative of Q with respect to Y term, hopefully you're thinking, ah yes, as you're increasing the Y component of your vector around your point, that corresponds with less
flow in than there is out, so both of these correspond to that idea of divergence that we're going for, and if you just add them up, this gives you everything
you need to know. And one thing that's pretty neat, and maybe kind of surprising, is that the way we just
came across this formula, and started to think about it, was in the simplified case, where you have, you
know, just pure movement in the X direction or pure
movement in the Y direction, but in reality, as we know, vector fields can look
much more complicated, and maybe you have something where you know, it's not just
in the X direction, and there's lots of things going on and you need to account for all of those, and evidently, just looking at the change in the X component with respect to X, or the change in the Y
component of the output with respect to the Y
component of the input, gives you all the
information you need to know. And basically what's going on here is that any fluid flow
can just be broken down into the X and Y components where you're just looking at each vector, you know, whatever vector you have, it could be broken down into it's own X and Y components and if you wanna think kind of concretely about the fluid flow idea, maybe you'd say that for your point, if you're
looking at a point in space, you picture a very small box around it, and the reason you only need to think about X components and Y components is that you're only really looking at, you know, what's going on
on the left and right side, and then you can kind of calculate what the divergence
according to fluid flowing in through those sides is, and then you just look at kind of, fluid flowing through
the top or the bottom, and if you kinda shrink this box down, all you really care about is
those two different directions, and anything else, anything that's kind of a diagonal into it, is
really just broken down into what's the Y component there, what's the, you know,
how is it contributing to movement up through that
bottom part of the box, and then what's the X component, how's it contributing to movement through that side part of the box. But anyway, I mean the upshot here is just that the formula for divergence only involves these two components.