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

Current time:0:00Total duration:6:17

so here I want to talk about the gradient in the context of a contour map so let's say we have a multivariable function a two variable function f of X Y and this one is just going to equal x times y so we can visualize this with a contour map just on the XY plane so what I'm going to do is I'm going to go over here I'm going to draw my y-axis and my x-axis right so this right here represents X values this represents Y values and this is entirely the input space and I have a video on contour maps if you are unfamiliar with them are feeling uncomfortable and the contour map for x times y looks something like this and each one of these lines represents a constant value so you might be thinking that you have you know let's say you want to the constant value for f of x times y is equal to 2 would be one of these lines that would be what one of these lines represents and the way you could think about that for this specific function is you're saying hey when is x times y equal to 2 and let's kind of like the graph y equals 2 over X and that's that's where you would see C something like this so all of these lines they're representing constant values for the function and now I want to take a look at the gradient field and the gradient if you'll remember is just a vector full of the partial derivatives of F and let's just actually write it out the gradient of F with our little del symbol is a function of x and y and it's a vector valued function whose first coordinate is the partial derivative of F with respect to X and the second component is the partial derivative with respect to Y so when we actually do this for our function we take the partial derivative with respect to X it takes a look X looks like a variable Y looks like a constant the derivative of this whole thing is just equal to that constant Y and then kind of the reverse for when you take the partial derivative with respect to Y Y looks like a variable X looks like a constant and the derivative is just that constant X and this can be visualized as a vector filled in the xy-plane as well you know at every given point XY so you kind of go like x equals 2 y equals 1 let's say so that would be x equals 2 y equals 1 you would plug in the vector and see what should the output and at this point the point is 2 1 the desired output kind of swaps those so we're looking somehow to draw the vector 1 2 so you would expect to see the vector that has an X component of 1 and a Y component of 2 something like that but it's probably going to be scaled down because of the way we usually draw vector fields and the entire field looks like this so I'll go ahead and erase what I had going on since this is a little bit clearer and remember we scale down all the vectors the color represents length so red here is super long blue is going to be kind of short and one thing worth noticing if you take a look at all of the given points around if the vector is crossing a contour line its perpendicular to that contour line wherever you go you know go down here this vector is perpendicular to the contour line over here perpendicular to the contour line and this this happens everywhere and it's for a very good reason and it's also super useful so let's just let's just think about what that reason should be let's let's zoom in on a point so I'm going to clear up our function here clear up all the information about it and just zoom in on one of those points so let's say like right here I'll take that guy and kind of imagine zooming in and saying what's going on in that region so you've got some kind of contour line and it's swooping down like this and that represents some kind of value let's say that represents the value F equals 2 and you know it might not be a perfect straight line but the more you zoom in the more it looks like a straight line and when you wouldn't want to interpret the gradient vector if you remember in the video about how to interpret the gradient in the context of a graph I said it points in the direction of steepest descent so if you imagine all the possible vectors kind of pointing away from this point the question is which direction should you move to increase the value of F the fastest and there's two ways of thinking about that one is to look at all of these different directions and say which one increases X the but another way of doing it would be to get rid of them all and just take a look at another contour line that represents a slight increase all right so let's say you you're taking a look at a contour line another contour line something like this and maybe that represents something that's right next to it like two point one that represents you know another value that's very close and if I were a better artist and this was more representative this would be it would look like a line that's parallel to the original one because if you change the change the output by just a little bit the set of end points that look like it is pretty much the same but just shifted over a bit so another way we can think about the gradient here is to say of all of the vectors that move from this output of two up to the value of two point one you're looking at all of the possible different vectors that do that you know which one does it the fastest and this time instead of thinking the fastest as constant length vectors what increases it the most will be thinking constant increase in the output which one does it with the shortest distance and if you think of them as being roughly parallel lines it shouldn't be hard to convince yourself that the shortest distance isn't going to be you know any of those it's going to be the one it connects them pretty much perpendicular to the original line because if you think about these as lines and the more you zoom in the more they pretty much look like parallel lines the path that connects one to the other is going to be perpendicular to both of them so because of this interpretation of the gradient as the direction of steepest descent it's a natural consequence that every time it's on a contour line wherever you're looking it's actually perpendicular to that line because you can think about it as getting to the next contour line as fast as it can increasing the function as fast as it can and this is actually a very useful interpretation of the gradient in different contexts so it's a good one to keep in the back of your mind gradient is always perpendicular to contour lines great see you next video