Lecture 22: Gradient and Divergence

{'English - US': '/courses/mathematics/18-085-computational-science-and-engineering-i-fall-2008/video-lectures/lecture-22-gradient-and-divergence/ocw-18.085-f08-lec22_300k.SRT'}

Flash and JavaScript are required for this feature.

Download the video from iTunes U or the Internet Archive.

Instructor: Prof. Gilbert Strang




OK. So some of this will not be new to you. But maybe some of the insights or the ways of looking at it could be new. This is the background of vector calculus. So we have things like vector fields. That means I have a vector, , at each point, (x, y). So I could draw a little arrow at every point to show the direction and magnitude of that vector. I have a field of vectors.



OK, gradient first. First, what does it mean? If I have a function u, what does it is gradient tell me? And then the second is kind of a backwards question. Suppose I have the v. Is it the gradient of some u? So one direction, from u to v, and the second direction will be from v back to u when possible.


OK, now what do I learn by taking the gradient? So the gradient of u, this is my v, is the x derivative, which is 2x, and the y derivative, which is 2y. OK. Let me take a typical point on the curve and draw that gradient vector. So this is the x, y plane, this is the curve u equal constant. When I have a curve u equal constant and I draw the gradient of u, where does it point? This is the first and most important, simple idea about the gradient vector. The gradient vector points -- does the gradient vector point, could it point any old way? No. The gradient vector is perpendicular to the curve. And we can see that, for this simple example, that vector , that's a vector radially outwards, right, if here's the origin. And if, at this point, I don't know its coordinates, whatever they are, maybe 2, 1 or something, the gradient vector would be . It would be a multiple -- here's the position vector, . The point is, the gradient vector points out. Perpendicular to the curve. That's what the gradient tells you. It tells you, in this situation it's telling me which direction is perpendicular to the curve.

Now how do I understand that? How do I see that? I think of this -- and let me try to draw the whole surface, u=x+y^2. What would that whole surface look like? Let me try to put that picture -- this is a 2-D picture right now. It's sort of a cross-section. Let me put this 2-D picture into a 3-D picture to see. So the 3-D picture is a picture of the whole surface. u going up, x and y going around. And what kind of a curve, what kind of a surface do I have for that function, x squared plus y squared. Well, it grows, right? It's sort of, I use the word bowl. And we've seen it before. It sort of goes up, right, and it goes up faster and faster as I go out, because of the squares.

And now what I want to do is, suppose I take the cross-section, suppose I take this bowl. Do you see a beautiful bowl there? And now, I cut through it, horizontal cross-section, at the height c. What do I get if I take this surface in 3-D, and I cut through it by a plane, the plane at that height, c. So if the plane went through there, that distance was c. It cuts us a cross-section out of the bowl. And what's the cross section? It's the circle. It's this one. So out of the bowl, this plane is cutting this cross-section. This is height u equal constant. So I'm really intersecting one surface, the plane u equal constant, with the bowl. And the intersection of those two is the equipotential, the curve, u=c. Right? You see the two pictures?

And now, what does the gradient tell me in that picture? What does the gradient of u tell me in that picture? Over here, it pointed outwards, but now we're going to kind of see why. So, it pointed outwards for this nice function, u. I could have made a more general function u, but let me just stay with this simple one.


Direction is, well for this special function you know the direction is, like, straight outwards, straight upwards. And how steep is it? What's the steepness? It's the size of, it's the magnitude of this vector, grad u. Which is the-- this is not -- how big is this vector? This is my vector, grad u. This is another shorthand notation for gradient. The size of that vector is the square root of, what? The length of a vector is the square root of the sum of the squares. So I have the length of v is the square root of 4x^2 + 4y^2. OK.

Now, it gets steeper and steeper, of course. The cross sections here would be all circles for this simple function. And the gradients would keep pointing out, and we'd have a function that comes from a surface like that.




And this brings us right away to the key identity from partial derivatives. OK. Can you see some condition that has to-- how can I connect these two equations, and therefore connect v_1 and v_2? That'll be the test for weather -- you could say, in matrix language, I'm asking whether is in the column space of the gradient. Is it something I can get from this tall thin matrix?

OK, they key idea is take the y derivative of that equation, d second u/dydx. And take the x derivative of this equation. dv_2/dy. dx is the second derivative of u, respect to the x derivative of the y derivative. OK. So it's like I'm operating on the equations. I'm doing what I'm allowed to do, I'm doing the same thing to both sides of each equation. Now I'm going to eliminate. And what am I going to find? What's the key point here?




Can I just throw out a question that you might think about? We already have seen, so often now, the second derivative, like v_xx. Or u_xx, suppose. So here's a little question to think about. So think. OK. I just want to bring finite differences in for a moment. u_xx we've got a handle on. We know that that's like u(x+h). And if there was a y, put in the y, minus 2u at x. And I can put in a y there, plus u(x-h,y). We've seen that. That'll be the x derivative, second x derivative -- sorry! Second x difference. Since we're taking x derivatives and x differences, it's x that moves, and y doesn't move. Just the central idea of partial derivatives. u_yy will be similar with y moving. And my question to you is -- and we could have asked it way way back -- what's a finite difference approximation to u(x,y), to the cross derivative? That equals what? I want to go to finite differences. OK, what finite differences? Which finite differences? Maybe that's a question to think about. If I can remember, I'll include it just as a small homework question for the homework on this material.


You're going to say, wait a minute. I learned about curl, and that doesn't look like the curl to me. So I'll say wait another minute. It's not that far off. OK, what's your objection? Your objection is that the curl is in three dimensional space. Right? When you saw curl, and of course it comes in this section of the book, we had functions of x, y, z. And the curl had three components. And those three components -- do you remember curl? I mean, if you remember curl, you're a good person. Because it's got this -- you sort of remember that it has things like this. Right? Sort of, differences of derivatives, and the indices follow a certain pattern. I'm saying that this is the natural -- this is the curl in a plane.


So what I want to say is that if I look, if I specialize too plane fields, to fields like these, then the only component of the curl that survives is this one. See, the other components of the curl -- which I'm not even writing down -- the other components of a curl have derivatives of v_3, but v_3 is zero. And they also have derivatives of these guys with respect to z. But they don't depend on z. So that's why all the other pieces of the curl, like, are automatically zero for a plane field. So that the only component that's significant, the test curl v equals zero, boils down to a test not on three things, but just on one. And that's the one. So because I want to stay mostly with plane fields and two dimensional problems, I just had to comment that, if the curl was to get in here, it would fit fine. And if I restrict the curl to the fields I'm working with, plane fields, then there's only one component I'll have to think about, it has to be zero to have a gradient field.


So let me show you what I mean by a vector field. I mean, at a typical point like x=1, y=0, the vector -- let's see, if x is one and y is zero, then what's the gradient at that point? , am I right? I won't draw it too big, or you won't be able to see a darn thing. OK, what about at the point (1, 1)? Which way is my vector field going? . So what's that look like? Plotting the vector field, v, at a bunch of points. So you get like a map of little arrows. So here it would go that way. Is that right? Huh. I wasn't expecting that, to tell the truth.

Let's see, so can I get some more points? Let's see. What if I have, there. What's -- at (1/2, 0). Then, v is . Where is this flow going? See, if the point is along this line, where y is equal to x, then the flow was going out along this line. Can you give me some other point here, just so we get some handle on this? There's the point (2, 1), let's say. Let me put it over a little bit. How about the point (2, 1). What's the vector if I just want to draw -- I'm just drawing here. And of course, code would do it much better than I'm doing. (2, 1), that gives me , right? So at (2, 4) is over two and up, it's like this. I think -- but I don't swear to it -- that if I connect all this -- see, now you have to take a big leap of faith. Imagine, like at every point we've got these little arrows, and I want to connect them up.



Hyperbolas -- you remember the Greeks, they had these conic sections. They had ellipses, they had parabolas, the marginal case, and then they had hyperbolas. And they all come from second degree things. If I have a x squared and 2bxy and cy squared equal one, that's one of those curves. And if it was x squared plus y squared equal one, it was a circle. If it was x squared plus 7y squared equal one, it would be an ellipse. The positive definite -- it all comes down to linear algebra, of course. If that little matrix is positive definite, so that means a and c are positive, and a c is bigger than b squared, you know the test for positive definite. What kind of curve do the Greeks have? What kind of equipotential -- what kind of a curve have we got here? An ellipse. If this curve, if that little matrix is indefinite, as, for example, here. So with this one, what would be the matrix, what's the matrix that goes with 2xy, if I match this with this. That's the matrix. There's no a squareds, there's no x squareds, there's no y squareds. And there are 2xy's, I think the matrix is that. So it's this nice symmetric matrix. Is that a positive definite matrix? Certainly not. It's indefinite. It's Eigenvalues are plus one and minus one, adding to the trace zero.

So indefinite matrices correspond to hyperbolas. And later on, definite matrices will correspond to elliptic partial differential equations. And indefinite matrices -- like Laplace -- and indefinite matrices will correspond to hyperbolic partial differential equations, like the wave equation. What's the -- now we're here. I didn't expect to get here -- what's the marginal case? What's the marginal case between positive definite and indefinite is -- semidefinite. Great. And what kind of a curve do you think comes when this little matrix is semidefinite. It's the one in between ellipses and hyperbolas. The marginal guy is a parabola. Right. So semidefinite would correspond to a parabola. Right. OK. Good.




OK. I've got to get to divergence here. Divergence. I should have said though, -- damn. There's more to say about gradients. That question of whether , the vector field, is this question. The question of is it the gradient of some u. So we now have a test. We now have a test. This is our test, right? That's our test. But I have to connect it with Kirchhoff's voltage law. Do you remember, we haven't talked so much about Kirchhoff's voltage law, but I'm connecting it with the discrete case, to add in a little more insight. What did Kirchhoff's voltage law say? In that case, a was a difference matrix. It was the incidence matrix for our graph. And the question was -- I have to take two moments to think about that.




OK. I had to say something about voltage law, because for the divergence, which I'm now going to get to -- whatever. Let me ask about divergence of w=0. What does that mean? That's going to be the equivalent of who's law. Please tell me. Which law is going to be the equivalent of -- divergence of w=0 is going to mean there's no source. Whatever goes in, comes out. Whose law is that? That's Kirchhoff again. Well, yeah, other people in physics. Right. But in our little world, it's the other Kirchhoff law. It's Kirchhoff's current law. It's the one, it's the A transpose Right? This is what we're thinking of as A transpose w equal zero. Kirchhoff's current law, in equals out.

How will I translate that in equal out for functions? Now I don't have -- on a graph, I just had the total flow, the net flow at every node. Notice the divergence is at every node. The circulation was around every loop. OK. So in equals out was just the sum of four things. OK, here I'm going to have in equal out -- how am I going to express in equal out? Divergence of w equals 0. Yeah, what I need is the divergence theorem. Let's just face it, we've got to have that.

So I have a region here. I have a w everywhere, w, . Then the divergence theorem. This is the great identity, which of course has a discrete form. OK. The divergence theorem says that if I integrate over the region, over this region, R, the divergence, that's (dw_1/dx+dw_2/dy)dxdy. So that's like telling me the source, I'm integrating over the source at every point. At every point here, this measures in minus out. But now, when I put the whole thing together by integrating, what's the right hand side of this equation? Do you know the divergence theorem? And let's remember it and see why it's so.

What I'm doing is in equals out for the whole region at once. Right? When I this is like in equal out at a point. But now I'm putting all the points together. So the only way out will be out through the boundary. And so I'll need to say how much flows out. This is the total source, the total in equal out inside. The only way to get out is through the boundary. So this is the integral around the boundary of -- so what's the flow out? It's, yeah, it's somehow -- think now what should go there.


