welcome back all right so we're talking about vector calculus div grad and curl
divergence gradient and rotation of your vector field today i'm talking about the gradient
okay and notice that i have already gotten too lazy to include my little over bars i'm basically
going to drop these but we know that this operator is a vector of partial derivatives so
the grad operator is partial partial x partial partial y in two dimensions
if in three dimensions there would be a partial partial z i'm going to make my life easy and for
now just look at it in 2d and the gradient of a scalar function f so if i have some scalar
f of x and y just recall that the gradient of f sometimes this is also called grad of f
is a vector field so it takes a scalar and creates a vector field partial f partial x partial
f partial y so when you hit grad with an f you literally just put in f here so if i had grad f
there would be an f here and you would apply the partial partial x to f and the partial partial y
to f and you would have those in the two the two components of your vector output very simple to
compute we could create an example for example if f was i don't know x squared plus y squared
then the gradient of f is going to be the partial of this with respect to x which is 2x
in the first component and the partial of this with respect to y in the second component to y
and essentially what that's going to do if i plot that as a vector field in x and y where maybe this
is the origin what we're going to have is as x and y get bigger this vector field gets bigger
in the x direction so it starts off small in the x direction and gets bigger and bigger
if i start in the y direction for larger y it gets bigger and bigger and similarly
on the diagonals the farther i go it gets bigger and bigger in kind of all of the directions
so very very intuitive easy to compute for a given scalar function x squared plus y
squared this kind of makes sense because this function also gets bigger and bigger
as i get higher in radius x squared plus y squared literally uh is like a big paraboloid if i look
down you know on this kind of x y and if i look down on that in this x y coordinates it kind of
makes sense that my gradient increases as i go farther away because this gets steeper and steeper
okay so that's how you compute the gradient this is kind of mathematically what it is
a couple of interesting properties here the gradient is a linear operator in fact this nabla
operator this del operator in general is a linear operator so grad is linear which specifically
means that if i take the gradient of some function f1 plus another function f2 it equals
the gradient of f1 plus the gradient of f2 and you can convince yourself that this is true
because basically if i had you know f1 plus f2 i would take the partial of the sum of them
on in both rows and the partial derivative is a linear operator so
partial of f1 plus f2 is partial of f1 plus partial of f2 so you can verify that this is true
and also that the gradient of some constant a times f is that constant times the gradient of
f so this is really important linearity means that superposition holds if i write down a differential
equation in terms of the gradient operator it's a linear differential equation and superposition
will hold if i have two solutions and i add those solutions there's still a solution when
you add them together so linearity is a really important property for differential equations and
for operators in general and i just want to point out that the gradient is in fact a linear operator
okay a couple more examples of the gradient this is one that i've given you a few times but i really like it so
If i take the gradient of a temperature field T(x,y)
and let's say that the temperature field is going from hotter to colder
Okay let's say, maybe I have a blow torch, and this is a metal plate, and I hit it with a blow torch for 10 seconds
and then I let it go so it's hot in the middle cold on the outside
the gradient of this temperature will be a vector at every point. I will have a grad(T)
and that grad(T) is a vector of partial T / partial x and partial T / partial y ...
it will literally have an arrow direction telling me how fast that temperature changes in the x
and y directions and every point it will point in the direction of the maximum rate of change
so the gradient of temperature tells me what direction is locally the fastest way to climb
that temperature gradient. It's kind of why the name stuck, and so I always like to give a
homework question or an exam question to my students... and I think they all think I'm crazy
...which is okay... You're an ant flying around in a room and you're cold, or sorry ants don't fly,
you're a bee flying around in a room and you're cold and there's a heat source, so in what direction
do you fly to get there as fast as possible and if they have the temperature distribution, all they
have to do is compute the gradient at that bee's location right now and they'll go towards that as fast as possible
Again, I mentioned earlier this is how we optimize functions in lots of optimization
problems mathematically is by gradient descent. I would literally take steps along the gradient
direction until i climb this hill, and that's a pretty fast, efficient way of finding the optimum
value -- the maximum or the minimum -- of a function that's how we train machine learning algorithms
like deep neural networks with stochastic gradient descent.
Exact same gradient. Sometimes it's a bee flying around in a room sometimes it's a billy goat climbing a mountain as fast as possible
that billy goat still computes the gradient of the altitude to climb as fast as possible
okay good um a few other things i want to point out
you can use this gradient to compute what's called a directional derivative
so i'll just write that out here so the directional derivative
um
and essentially the directional derivative is literally the derivative
the derivative of f my scalar function f in a direction
v so this is kind of cool we're used to being able to take the derivative of our function in the x
direction that's just partial partial x we're used to being able to take it in the y direction that's
partial partial y but what if i say okay take it in this v direction i've got some random vector
v how do i take the derivative of f the rate of change of f in that direction is f getting
bigger smaller by how much and mathematically we say that this is the directional derivative
of f in the v direction this is how we write it it's the derivative of
f in the v direction and it's super simple it doesn't get simpler than this it's just v
dotted with the gradient of f remember the gradient of f is a vector and i can dot it
into this direction v so i literally just see like where is that where is you know grad t
grad f pointing and i dot it with v and that tells me how fast and if they're perpendicular
then the directional derivative is zero actually i kind of drew it so that the gradient is almost
perpendicular to this v in which case the directional derivative would be zero
which means if i take a small step in that direction my temperature doesn't change
there are directions like that and you have to normalize by the length of this
v because someone might give you like a v that's 10 units long or 0.10 units long and it shouldn't
matter what the length of v is so the directional derivative also super important
okay one more example i want to really like drive home how much i love the gradient
how useful it is and i feel like when i'm learning math i like to see it a lot of
different ways because maybe one of them clicks so the gradient allows me to compute the rate
of change of a scalar field in the x and y directions that's literally the rate of change
in the x direction the rate of change in the y direction it allows me to compute directions
of fastest rate of change it also allows me to take the derivative in any old direction
and uh another example of the gradient beyond the temperature distribution is uh gravitational
potentials okay so an object maybe i'll do a pink over here so another application is an object
in a gravitational
field okay and i want to kind of try to remember how to actually do this so
we have newton's law of gravity
okay and newton's law is something like uh
the force and remember force has a direction it's a vector the force is equal to um if i have like
i should probably draw a planet here so if i have planet earth
let's actually make this kind of fancy right so we got some some continents
really bad at drawing earth okay we've got some continents over here
earth earth has a gravitational field right and that gravitational field always points
towards the center of earth we know that that's true and in fact the gravitational
field is stronger the closer you are if you go way way out i'll only have a little force
a smaller force okay so it's always pointing into the center and it's bigger when you're
closer and you can write that down newton's law as minus little m times big m times the
gravitational constant divided by the radius cubed times some radius vector
where um how do i wanna say it so that's if i have some point out here with mass little m of course
earth has mass big m uh and this r vector is always pointing towards the center of the earth
okay this is always the vector pointing towards the center of the earth
and this has magnitude r so i need another r down here we know that the force decreases as r squared
and then i need another r to counteract the magnitude of this and that's it the force
always points in the radial direction and it has magnitude given by this expression here
okay that's all fine and good this has nothing to do with the gradient so far
except that this is a potential field this is equal to minus the gradient of the potential
energy of this object so any object at some radius r is going to have a potential energy
and its potential energy increases the farther out you go in r and literally the gradient of
that potential is what gives rise to this uh this force law here where the gravitational potential
uh the gravitational potential v is equal to uh minus little m big m big g over little r um
that's it literally the potential increases as you as you go farther away and if you grab this object
you arrive at this force law vector field so i highly encourage you to actually do this exercise
write this out in cartesian xy or xyz coordinates and compute its gradient and convince yourself
that it is actually the right gravitational potential okay very kind of useful idea.
This is also useful if you have a roller coaster on earth. I love roller coasters... in fact I'm filming this at
7:00 pm the day before I'm about to move across the country to California for sabbatical...
that's how much I love gradients and I love teaching you about gradients
and on the way, we're going to go to Santa Cruz and we're going to ride roller coasters at their fair.
And the exact same potential -- if I write the potential energy of a car
on a roller coaster, I can create a vector field of the forces at every point
on that roller coaster, by computing the gradient. Okay, that's how gravity is acting
on the car at all of those locations. So this is the gradient... we're gonna do the same
thing for div and curl and then we're gonna start putting these objects together and showing how
these partial derivatives and these operators are the building blocks
of vector calculus, conservation laws, and partial differential equations. All right thank you.