< Return to Video

Gradient of a scalar field

  • 0:00 - 0:01
  • 0:01 - 0:04
    In the last video we had a
    three-dimensional surface,
  • 0:04 - 0:08
    where the height z was
    a function of x and y.
  • 0:08 - 0:11
    And it gave us surface in
    three-dimensional space.
  • 0:11 - 0:15
    Now let's try to get our heads
    around what the gradient
  • 0:15 - 0:19
    of a function of three
    variables looks like.
  • 0:19 - 0:23
    So the easiest one for me to
    imagine is a scalar field.
  • 0:23 - 0:24
    So what's a scalar field?
  • 0:24 - 0:28
    One that I find fairly
    intuitive is temperature in
  • 0:28 - 0:29
    a three-dimensional room.
  • 0:29 - 0:34
    So let's say the temperature
    in a room is a function of
  • 0:34 - 0:36
    where I am in the room.
  • 0:36 - 0:43
    So let's say it's a function of
    my x, y, and z coordinates.
  • 0:43 - 0:45
    And I don't know, I have never
    actually modeled temperature.
  • 0:45 - 0:50
    But let's say I have, I don't
    know, a 20 kelvin-- actually,
  • 0:50 - 0:52
    let me make it so that our
    vector field works out right.
  • 0:52 - 0:54
    Let's say we have a 10
    kelvin heat force in
  • 0:54 - 0:58
    the center of our room.
  • 0:58 - 1:01
    I can imagine as you go further
    and further away from that
  • 1:01 - 1:03
    heat source it's going to
    get colder and colder.
  • 1:03 - 1:05
    So let's say that the
    temperature function.
  • 1:05 - 1:08
    And let's say that center of
    the room is at the coordinates
  • 1:08 - 1:09
    x, y, and z is equal to 0.
  • 1:09 - 1:11
    So let's say our temperature
    function-- I'm just making this
  • 1:11 - 1:24
    up, I don't know if this is an
    accurate model of temperature--
  • 1:24 - 1:32
    it's equal to 10 times e
    to the minus r squared.
  • 1:32 - 1:33
    Now why did I say r?
  • 1:33 - 1:34
    I said it's a function
    of x, y, and z.
  • 1:34 - 1:39
    Well I'm just saying that it
    exponentially decays as you
  • 1:39 - 1:42
    get further and further
    away from that source.
  • 1:42 - 1:44
    Kind of radially further and
    further away from that source.
  • 1:44 - 1:46
    So what's the radial
    distance away?
  • 1:46 - 1:48
    And this actually isn't that
    relevant to learning gradients,
  • 1:48 - 1:50
    but let's get a little
    intuition about what that
  • 1:50 - 1:54
    actual temperature function--
    how it actually changes as
  • 1:54 - 1:56
    you go through the room.
  • 1:56 - 2:01
    So the radius away from the
    center, that's just going to be
  • 2:01 - 2:06
    r squared is just x squared
    plus y squared plus z squared.
  • 2:06 - 2:09
    That's just the Pythagorean
    theorem in three dimensions.
  • 2:09 - 2:11
    So let's write our
    temperature function.
  • 2:11 - 2:19
    So let's write temperature as
    a function of x, y, and z is
  • 2:19 - 2:30
    equal to 10 e to the minus x
    squared plus y squared plus z
  • 2:30 - 2:33
    squared-- which is exactly
    what I wrote up here.
  • 2:33 - 2:36
    Instead of x squared plus y
    squared plus z squared, I wrote
  • 2:36 - 2:38
    r squared, just to kind of give
    you the intuition that this
  • 2:38 - 2:41
    expression is just saying the
    square of the distance as we
  • 2:41 - 2:45
    get away from the center of
    our room, or from the
  • 2:45 - 2:47
    coordinate 0, 0, 0.
  • 2:47 - 2:48
    But that's not what
    we're learning here.
  • 2:48 - 2:51
    But I want you to understand,
    at least conceptualize this,
  • 2:51 - 2:53
    it's hard to draw
    a scalar field.
  • 2:53 - 2:57
    All a scalar field means is
    that in any point in this
  • 2:57 - 3:00
    base-- and in this case we're
    dealing with three-dimensional
  • 3:00 - 3:05
    space-- at any point in that
    space we can associate a value.
  • 3:05 - 3:06
    And that makes sense.
  • 3:06 - 3:08
    If you were to take a
    thermometer and measure any
  • 3:08 - 3:11
    point in space in the room
    that you're in right now,
  • 3:11 - 3:13
    you would get a temperature.
  • 3:13 - 3:15
    You wouldn't get a temperature
    and a direction, so it's
  • 3:15 - 3:16
    not a vector field.
  • 3:16 - 3:18
    You would just get
    a temperature.
  • 3:18 - 3:20
    And that's why it's
    called a scalar field.
  • 3:20 - 3:21
    Associated with every
    coordinate is just
  • 3:21 - 3:23
    a temperature.
  • 3:23 - 3:28
    So how would we view the
    gradient of this function?
  • 3:28 - 3:31
    Well the gradient of this
    function is going to tell us in
  • 3:31 - 3:33
    which direction-- and actually,
    the gradient of this function
  • 3:33 - 3:36
    is going to generate a vector
    field, because it's going to
  • 3:36 - 3:40
    tell us in which direction
    do we have the largest
  • 3:40 - 3:42
    increase in temperature.
  • 3:42 - 3:45
    And also, the magnitude of
    those vectors in that vector
  • 3:45 - 3:47
    field will tell us how large
    of an increase in temperature
  • 3:47 - 3:48
    we are looking at.
  • 3:48 - 3:53
    Or you can kind of
    view it as almost a
  • 3:53 - 3:55
    three-dimensional slope.
  • 3:55 - 3:56
    Hope that doesn't confuse you.
  • 3:56 - 3:59
    So let's compute the gradient,
    and then I'll show you a
  • 3:59 - 4:03
    diagram that might make things
    a little bit more intuitive.
  • 4:03 - 4:07
    Let me erase this
    thing down here.
  • 4:07 - 4:09
    And I'm going to switch from
    this blue color, because
  • 4:09 - 4:15
    it's a little nauseating.
  • 4:15 - 4:23
    So the gradient of T is going
    to be equal to the partial
  • 4:23 - 4:28
    derivative T with respect to x
    times the unit vector in the x
  • 4:28 - 4:34
    direction, plus the partial
    derivative of the temperature
  • 4:34 - 4:39
    function with respect to y
    times the unit vector in the y
  • 4:39 - 4:44
    direction, plus the partial
    derivative of the temperature
  • 4:44 - 4:49
    function with respect to z
    times the unit vector
  • 4:49 - 4:50
    in the z direction.
  • 4:50 - 4:52
    And now we just plug and
    chug and figure out the
  • 4:52 - 4:54
    partial derivatives.
  • 4:54 - 5:00
    So the gradient of T is equal
    to-- now you might be daunted.
  • 5:00 - 5:05
    Oh, I have an e to this three
    variable function, how do I
  • 5:05 - 5:06
    take the partial derivative?
  • 5:06 - 5:08
    Remember, if you're taking the
    partial derivative with respect
  • 5:08 - 5:12
    to x you just pretend like the
    y's and the z's are constants.
  • 5:12 - 5:14
    So let's do that.
  • 5:14 - 5:20
    So let's take the derivative
    of the inside function.
  • 5:20 - 5:20
    That's the way I view it.
  • 5:20 - 5:23
    So minus x squared plus y
    squared plus z squared,
  • 5:23 - 5:24
    with respect to x.
  • 5:24 - 5:27
    So you could distribute
    this minus if you like.
  • 5:27 - 5:29
    So it'd be minus x
    squared minus y squared
  • 5:29 - 5:31
    minus z squared.
  • 5:31 - 5:34
    So the derivative of that with
    respect to x is just going to
  • 5:34 - 5:37
    be-- these are just constants,
    so the derivative with
  • 5:37 - 5:38
    respect to x is just 0.
  • 5:38 - 5:41
    So the derivative is minus 2x.
  • 5:41 - 5:42
    Right?
  • 5:42 - 5:46
    Minus 2x is the derivative
    of minus x squared.
  • 5:46 - 5:50
    Minus 2x times the
    derivative of the outside.
  • 5:50 - 5:53
    Well, what's the
    derivative of e to the x?
  • 5:53 - 5:55
    The derivative of e to
    the x is e to the x.
  • 5:55 - 5:58
    That's why e is such
    an amazing number.
  • 5:58 - 6:01
    And this 10 here, this is just
    a constant that when you take
  • 6:01 - 6:05
    the derivative of a constant
    times something the
  • 6:05 - 6:07
    constant carries over.
  • 6:07 - 6:11
    So the derivative of the
    outside expression, the way I
  • 6:11 - 6:18
    imagine it, is equal to 10 e
    to the minus x squared plus
  • 6:18 - 6:22
    y squared plus z squared.
  • 6:22 - 6:27
    And then all of that times the
    unit vector in the i direction.
  • 6:27 - 6:30
    Right?
  • 6:30 - 6:34
    And now we can do the same
    thing for the y direction.
  • 6:34 - 6:36
    So plus-- what's the
    partial derivative of
  • 6:36 - 6:37
    this with respect to y?
  • 6:37 - 6:38
    Well it's going to
    look very similar.
  • 6:38 - 6:40
    The partial derivative of this
    inner function with respect
  • 6:40 - 6:42
    to y, it's minus y squared.
  • 6:42 - 6:43
    So it's minus 2y.
  • 6:43 - 6:47
  • 6:47 - 6:48
    And then the derivative
    of the whole thing is
  • 6:48 - 6:51
    just itself again.
  • 6:51 - 6:56
    So times 10 e to the
    minus x squared plus y
  • 6:56 - 6:58
    squared plus z squared.
  • 6:58 - 7:02
    And then all of that times
    the unit vector in the
  • 7:02 - 7:05
    y direction times j.
  • 7:05 - 7:10
    And then finally, the partial
    derivative of the temperature
  • 7:10 - 7:12
    function with respect to z.
  • 7:12 - 7:23
    And that's just minus 2z times
    10 e to the minus x squared
  • 7:23 - 7:26
    plus y squared plus z squared.
  • 7:26 - 7:27
    This is just the chain rule.
  • 7:27 - 7:29
    And I'm treating the other two
    variables that I'm not taking
  • 7:29 - 7:32
    the partial derivative with
    respect to, as constants.
  • 7:32 - 7:37
    And then all of that times the
    unit vector in the k direction.
  • 7:37 - 7:40
    And we could simplify
    this a little bit.
  • 7:40 - 7:42
    You could have
    minus 2x times 10.
  • 7:42 - 7:44
    That's minus 20x.
  • 7:44 - 7:45
    Let me write it up here.
  • 7:45 - 7:50
    So the gradient of the
    temperature function is equal
  • 7:50 - 7:58
    to minus 20 e to the minus x
    squared plus y squared-- you
  • 7:58 - 8:08
    probably can't read this-- plus
    z squared, times i minus 20y.
  • 8:08 - 8:10
    And actually, I'm not going to
    go into that, because I realize
  • 8:10 - 8:11
    I'm running out of time.
  • 8:11 - 8:15
    I think you can simplify
    this algebraically.
  • 8:15 - 8:18
    But anyway, the more important
    thing is I always find with
  • 8:18 - 8:20
    gradients it's easy to
    calculate them, but the
  • 8:20 - 8:21
    intuition-- oh sorry.
  • 8:21 - 8:22
    This is also included.
  • 8:22 - 8:23
    This is a k right here.
  • 8:23 - 8:26
    The harder part is
    the intuition.
  • 8:26 - 8:28
    So let's get an intuition of
    what this gradient function
  • 8:28 - 8:29
    will actually look like.
  • 8:29 - 8:30
    So what would happen.
  • 8:30 - 8:33
    If you wanted to know the
    gradient at any point in space,
  • 8:33 - 8:35
    you would substitute an
    x, y, and z in here.
  • 8:35 - 8:41
    So you could write it as
    the gradient function is a
  • 8:41 - 8:44
    function of x, y, and z.
  • 8:44 - 8:48
    Remember, T, the temperature at
    any point, was a scalar field.
  • 8:48 - 8:50
    At any point in three
    dimensions it just
  • 8:50 - 8:51
    gave you a number.
  • 8:51 - 8:53
    Now when you have the gradient,
    at any point in three
  • 8:53 - 8:55
    dimensions it gives
    you a vector.
  • 8:55 - 8:55
    Right?
  • 8:55 - 8:58
    Because it has i, j,
    and k components.
  • 8:58 - 9:00
    Where the magnitude are the
    partial derivatives, and
  • 9:00 - 9:03
    then the direction is
    given by i, j, and k.
  • 9:03 - 9:07
    So we've gone from having a
    scalar field to a vector field.
  • 9:07 - 9:08
    And let's see what
    it looks like.
  • 9:08 - 9:12
  • 9:12 - 9:14
    And let me make it bigger so we
    can explore it a little bit.
  • 9:14 - 9:17
  • 9:17 - 9:19
    I think that's pretty good.
  • 9:19 - 9:23
    So this is the vector field.
  • 9:23 - 9:26
    This is actually the gradient
    of the function that
  • 9:26 - 9:29
    we just solved for.
  • 9:29 - 9:34
    And as you can see, at any
    point-- and when this graphing
  • 9:34 - 9:37
    program that did it, it just
    picked different points and it
  • 9:37 - 9:39
    calculated the gradients at
    that point, and then it
  • 9:39 - 9:40
    graphed them as vectors.
  • 9:40 - 9:45
    So the length of the vectors
    are just the magnitudes of
  • 9:45 - 9:46
    the x, y, and z components.
  • 9:46 - 9:50
    And then you add them together
    like you would add any vectors.
  • 9:50 - 9:54
    And then the direction is given
    by the relative weighting of
  • 9:54 - 9:56
    the i, j, and k components.
  • 9:56 - 9:58
    And as you can see, the
    intuition is pretty
  • 9:58 - 10:00
    interesting.
  • 10:00 - 10:04
    As you get closer and closer to
    our heat source, the rate at
  • 10:04 - 10:07
    which the temperature
    increases, increases!
  • 10:07 - 10:08
    Right?
  • 10:08 - 10:11
    The vectors as you get closer,
    get bigger and bigger.
  • 10:11 - 10:11
    And let me zoom in.
  • 10:11 - 10:15
    Let's actually fly in
    to the vector field.
  • 10:15 - 10:19
  • 10:19 - 10:21
    So we're now within
    the vector field.
  • 10:21 - 10:24
    And you can see as we get
    closer and closer to the center
  • 10:24 - 10:28
    of our heat source, the
    vectors, the rate at which the
  • 10:28 - 10:32
    temperature increases, gets
    bigger and bigger and bigger.
  • 10:32 - 10:34
    Anyway, I hope I
    didn't confuse you.
  • 10:34 - 10:37
    When I first learned gradients,
    I think the computation is
  • 10:37 - 10:38
    relatively straightforward.
  • 10:38 - 10:39
    It's just partial derivatives.
  • 10:39 - 10:42
    But the intuition is always
    the interesting thing.
  • 10:42 - 10:44
    And hopefully this temperature
    analogy-- and not even
  • 10:44 - 10:49
    analogy-- this temperature
    model will make a
  • 10:49 - 10:49
    little sense to you.
  • 10:49 - 10:51
    But it applies to pretty
    much any scalar field.
  • 10:51 - 10:54
    Anyway, I'll see you
    in the next video.
Title:
Gradient of a scalar field
Description:

Intuition of the gradient of a scalar field (temperature in a room) in 3 dimensions.

more » « less
Video Language:
English
Duration:
10:54

English subtitles

Revisions