matlab-enhanced Swiki= [View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide]

Marius Popescu










Gradients


The Concept

The general differentiation rule that we have dealt with in one variable cases goes as follows:
f (x+h) - f (x)
h
as h->0

In the multivariable case we have the vector x and h with same number of variables < x 1,x2,x3,...,xn> in the formula:
f (x+h) - f (x)
h

However we cant devide by a vector h. So going back to the single variable case we convert the formula to:
f(x+h) - f (x)= f'(x) + o(h)

where o(h) =
g(h)
]h[
as h->0
Note: ]x[ denotes the absolute value
The Proof is fairly easy:
f (x+h) - f (x)
h
...= f'(x)

f (x+h) - f (x) -f'(x)h
h
...= 0

f (x+h) - f (x) - f'(x)h = o(h)

f (x+h) - f (x) = f'(x)h + o(h)

Converting this back to vectors gives:
f (x+h) - f (x) = y.h + o(h)

This vector y we call the gradient of f and is denoted Беf however i will use Vf from now on.

The gradient is formed by multiplying the respective partial derivatives to the unit vector as such:
Vf (x)= df/dx(x)i + df/dy(x)j + df/dz(x)k






A quick review of partial derivatives

When we do partial derivatives we derive with respect to a single variable at a time leaving the others constant. The formula is pretty basic:
(the two variable case, any additional variables follows similar pattern)
f x(x,y)=
f(x+h,y) - f(x,y)
h
as h->0

and

f y(x,y)=
f(x,y+h) - f(x,y)
h
as h->0

Example:
f= 2xy2 + e2xy + 3y3

fx= 2y2 + 2e2xy

fy= 4xy + e2x + 9y2

Of course fx can also be written as df/dx

and we can note that we can still write partial derivatives in vector form as such:
(note:(x= (x,y) this is a two variable case, once again three variables follows a similar pattern)

df/dx=
f(x + hi) - f(x)
h
as h->0

and

df/dy=
f(x + hj) - f(x)
h
as h->0

and note that we could use any unit vector u as in

f(x + hu) - f(x)
h
as h->0

If u is not an orthogonal vector, which it very well can be, then we call this derivative a directional derivative in direction of u






Example
f= 2xy2 + e2xy + 3y3

Vf=[2y2 + 2e2xy]i + [4xy + e2x + 9y2]j

Some Formalas:
V[f(x) + g(x)]= Vf(x) + Vg(x)
V[af(x)]=aVf(x)
V[f(x)g(x)]=f(x)Vg(x) + Vf(x)g(x)
Chain rule:d[f(r(t))]/dt=Vf(r(t)).r'(t)
where r(t) is a vector function with variable t such r(t)=x(t)i + y(t)j etc. so we can replace (x,y) with (x(t),y(t))
Proof:
f(r(t+h))-f(t))
h
...= Vf(r(t)).r'(t)
start off with the Mean Value theorem (explained later) since we can induce that there exists a line segment between point r(t+h) and r(t). we get:

f(r(t+h)) - f(r(t))= Vf(c(h)). [r(t+h)-r(t)]

then

f(r(t+h)) - f(r(t))
h
...= Vf(c(h)). [(r(t+h)-r(t))/h]

as h->0 two things happen

Vf((h))->Vf((t)) [since we set c= a + t(b-a)]

and

[(r(t+h)-r(t))/h]-> r'(t)

Some Applications of Gradients

  • Directional Derivative

  • Mean Value

  • Tanent lines

  • Maxima and Minima

  • And of course theres more



The directional derivative using a gradient is quite simple and is easy to understand:

f'u(x)=Vf(x).u

and it follows that

f'u(x)=compuVf(x)





Example

f(x,y)=x2/4 + y2/9 with u=1/5(3i + 4j) [note: always remember to unitize] using point (2,3)

Vf=(x/2)i + (2y/9)j
Vf(2,3)=(1)i + (2/3)j
(now apply formula)
Vf(2,3).u=((1)i + (2/3)j).1/5(3i + 4j)
3/5 + 8/15 = 17/15

The Mean Value theorem is a little longer to prove but not as complicated, if i had no life and i actually bothered to write all that code down i might, but later. Even though I always think its important to know the proof, for now just be satisfied with the formula:

f(b) - f(a)=Vf(c).(b - a)

Where a and b are two points with a line segment between them that is differentiable at every point along the line. C is the point at which the slope equals the slope of that line segment.

Tangent lines require that f(x,y)=c c is a constant. Then we find a (xo,yo) on that curve which we wish to find the tangent to. The gradient at the selected point is naturally the normal vector in 2D and 3D etc. thus

Vf(xo,yo)=df/dx(xo,yo)i + df/dy(xo,yo)j

Its easy to see that the line perpendicular to this normal line is the tangent and how the following formula makes sense since the dot product of the tangent and gradient is 0.

Vf(xo,yo)=df/dy(xo,yo)j - df/dx(xo,yo)i

In three dimensions we form a plane. The selected point is xo and once again it makes sense that every vector perpendicular to the normal vector would form a tangent plane on that point. So:

Vf(xo).(y-xo)

where y is a point on the tangent plane

recall also that f(x,y,z)=c

So the formula for the tangent plane is as follows:

df/dx(xo,yo,zo)(x-xo) + df/dy(xo,yo,zo)(y-yo) + df/dz(xo,yo,zo)(z-zo) = 0

The normal line in vector notation looks like

r(t)=ro + Vf(xo)t






Example
find the normal vector and tangent line xy2 - 2x2 + y + 5x = 6 P(4,2)

Vf=(y2 -4x +5)i + (2xy +1)j

df/dx(4,2)=-7 df/dy(4,2)=17

  • 7(x - 4) + 17(y - 2) = 0

  • 7x + 28 +17y -34=0

17y= -6 -7x



The Minima and Maxima are quite easy to find as well. Its where

Vf(xo)=0 or is undefined.

and you can check if it is a minima or maxima if a neighbor point is below or above it. thus:

f(xo) > f(x) is a maximum
f(xo) < f(x) is a minimum

However the second partials test is useful and more powerful. it states

A=d2f/dx2(xo),yo))
B=d2f/dxdy(xo),yo))
C=d2f/dy2(xo),yo))
D=AC-B2

if D 0 then the point is a saddle
if D > 0 then the point:
is a local minimum if A > 0
is a local maximum if A 0






Example
f= x2 - y2 + 4xy +5y
Vf(x,y)=(2x + 4y)i + (-2y + 4x + 7)j
Vf(x,y)=0
2x + 4y=0 and -2y + 4x + 5=0 2x + 5=6y so the point (-4,2) satisfies the equation

The second partials are
A=2
B=4
C=-2

and

D=-4 - 16= -20 so the point is a saddle.



Thats it phew.

And so master chief saves the day.

the end



P.S. the background is a fractal. I hope to study them sometime




----
links to this page