Main content

### Course: Multivariable calculus > Unit 2

Lesson 2: Gradient and directional derivatives- Gradient
- Finding gradients
- Gradient and graphs
- Visual gradient
- Gradient and contour maps
- Directional derivative
- Directional derivative, formal definition
- Finding directional derivatives
- Directional derivatives and slope
- Why the gradient is the direction of steepest ascent

© 2024 Khan AcademyTerms of usePrivacy PolicyCookie Notice

# Gradient and contour maps

Gradient vectors always point perpendicular to contour lines. Created by Grant Sanderson.

## Want to join the conversation?

- So, when you show us the vector field of Nabla(f(x,y)) = <y;x>, you say that the more red the vector is, the greater is its length. However, I noticed that the most red vectors are those in the center (those that should be less red, because closer to the center, smaller the variables)(59 votes)
- I'm pretty sure that vector field color is wrong. If we assume that solutions for f(x,y) used for drawing contour lines are evenly spaced numbers exp. f(x,y)=2,4,6,8,10,12,... then the more dense contours further away from the center should represent steeper descent ( and vectors should have warmer color to them). I mean its a small mistake, but for someone trying to wrap his head around concept of gradients this will cause some headache.(21 votes)

- Given a vector field, is it always the gradient field of a function?(16 votes)
- Great question! Most vector fields are not gradient fields. I'll make videos on this soon, but some vector fields have the property of being "conservative vector fields". There are several equivalent ways to define a conservative vector field, which involve various topics you'll come across later on in multivariable calculus (line integrals, curl, etc.). A neat result is that only these conservative vector fields can be the gradient of some function.(22 votes)

- At4:05and5:49, the transcript reads "direction of steepest descent". Shouldn't the correct word be ascent? I'm not sure if this is just a typo or actually correct.(14 votes)
- Yes, he clearly says 'ascent' in both cases.(0 votes)

- At2:57, grant said red vectors are super long but they should be super small right ?(9 votes)
- I agree, I think the colors are wrong - the ones near the origin should be blue / small vectors.(9 votes)

- Does the orthogonality propierty of the gradient vector mantains as we go into higher dimensions? Is it orthogonal to level surfaces and so on?(6 votes)
- Yup! And the reasoning is almost entirely the same.(13 votes)

- where is the video on the contour map?(3 votes)
- At4:02

"It points at the direction of steepest descent"

Is it steepest descent, or ascent? Because the vectors in the top-right and bottom-left quadrants are all pointing outwards. And those points all give function outputs that steadily get higher and higher, don't they? And in opposition of that, the top-left and bottom right are pointing inwards, because those quadrants have negative heights, or drop-offs.(5 votes) - How can a 2D vector represent the direction of the steepest ascent in a 3D graph?(3 votes)
- It represents the change in the input space basically. Or another way of seeing it could be we want to fiind the quickest way to change z, and to change z we have to change x and y, so the quickest way to change z has to be in terms of x and y(3 votes)

- Gradient is always perpendicular to contour lines. Still not sitting with me 100%. May have to watch this a few times.

I understand that perpendicular distance will be the shortest and can involve the greatest gradient when moving from one contour line to the next. Why is that the focus?(2 votes)- 1)For consideration:Closer the contour lines,steeper is the curve.

2)To find the direction of steepest ascent we need to move in the direction in which we encounter the most number of contour lines per unit distance we travel in the X-Y plane

3)This direction has to be perpendicular to the current contour line on which we are standing(Since the shortest distance along two curves is along their common normals....)

4)Hence the gradient has to be perpendicular to the contour lines.(2 votes)

- At4:05(and later again at5:47) its said that the gradient points towards the steepest descent while referencing the previous video, which says that the gradient points towards the steepest ASCENT.

Is it safe to assume that this is just a small fumble? If not, what makes this gradient different compared to the previous one?(2 votes)- It should be ASCENT. The gradient vector lives in the function's input space and will point in the direction you should travel within the function's input space to increase the function value most vigorously.(2 votes)

## Video transcript

- [Voiceover] So here I want to talk about the gradient and 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
gonna equal x times y. So we can visualize
this with a contour map just on the xy plane. So what I'm gonna do is I'm gonna go over here. I'm gonna draw a y axis and my x axis. All right, so this right here represents x values. And 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 or 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 a the constant value for f of
x times y is equal to two. Would be one of these lines. That would be what one of
these lines represents. And a way you could think about that for this specific function is you saying hey, when
is x times y equal to two? And that's kind of like the graph y equals two over x. And that's where you would
see 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 field in the xy plane as well. You know, at every given point, xy, so you kind of go like x equals two, y equals one, let's say. So that would be x
equals two, y equals one. You would plug in the vector and see what should be output. And at this point, the point is two, one. The desired output kind of swaps those. So we're looking somehow to
draw the vector one, two. So you would expect to
see the vector that has an x component of one
and a y component of two. Something like that. But it's probably gonna 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 scaled
down all the vectors. The color represents length. So red here is super-long. Blue is gonna 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, it's perpendicular to that contour line. Wherever you go. You know, you go down here, this vector's perpendicular
to the contour line. Over here, perpendicular
to the contour line. And this happens everywhere. And it's for a very good reason. And it's also super-useful. So let's just think about
what that reason should be. Let's zoom in on a point. So I'm gonna clear up our function here. Clear up all of the information about it. And just zoom in on one of those points. So let's say like right here. We'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 two. 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 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 most? 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'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 2.1. That represents, you know,
another value that's very close. And if I were a better artist, and this was more representative, it would look like a line that's parallel to the original one. Because if you change the output by just a little bit, the set of in 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 2.1. You know, 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 of the fastest as constant-length vectors, what increases it the most, we'll 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 gonna be, you know, any of those. It's gonna be the one that 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 gonna 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 intepretation 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.