Application Center - Maplesoft

App Preview:

Calculus IV: Complete Set of Lessons

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

L1-DirectionalDiff.mws

Calculus IV with Maple
Copyright 2002, Dr. Jack Wagner
j.wagner@intelligentsearch.com


Lesson 1: Directional Derivatives

Topics : The directional derivative and non-linear transformations.  
Maple commands introduced:
ScalarMultiply, DirectionalDiff, Jacobian, fieldplot, evalVF

 

Given   f : R^n   -> R^n  , the directional derivative of f ( x )  in the direction v is defined as: Limit((f(x+t*v)-f(x))/t,t = 0)

>    restart: with(LinearAlgebra): with(VectorCalculus):

Let F  be a vector-valued function of four variables

>    F := (w, x, y, z) -><f(w, x, y, z), g(w, x, y, z), h(w, x, y, z), k(w, x, y, z)>:

>    F(w, x, y, z);

Vector(%id = 20336280)

Let v  be a direction along which we compute the derivative of F .

>    v := <a, b, c, d>;

v := Vector(%id = 20336480)

Let delta  be the difference quotient along direction v .

>    delta := (F(w + t * a, x + t * b, y + t * c, z + t * d) - F(w, x, y, z))/t;

delta := Vector(%id = 20707640)
delta := Vector(%id = 20707640)

The directional derivative of F  along v we find by taking the limit as t  goes to 0.

>    D[v](F) = limit(delta, t = 0);

D[Vector(%id = 20336480)](F) = Vector(%id = 20338560)
D[Vector(%id = 20336480)](F) = Vector(%id = 20338560)
D[Vector(%id = 20336480)](F) = Vector(%id = 20338560)
D[Vector(%id = 20336480)](F) = Vector(%id = 20338560)

This is conveniently written as a matrix equation.

>    D[v](f) = <<D[1](f) | D[2](f) | D[3](f) | D[4](f) >, <D[1](g) |D[2](g)| D[2](g) |D[2](g)> , <D[1](h) | D[2](h) | D[3](h) | D[4](h)> , <D[1](k) |D[2](k) | D[3](k)|D[4](k)> > * <<a, b, c, d>>;

D[Vector(%id = 20336480)](f) = Matrix(%id = 19686948)*Matrix(%id = 20646588)

Observe that each row of the matrix consists of  the components which result from operating on a component of F ,  with an operator variously called grad , del , nabla .  

>    del  =  <D[1]|D[2]|D[3]|D[4]>;

del = Vector(%id = 19735564)

In this notation:

>    D[v](f) = <<grad(f), grad(g), grad(h), grad(k)>> * <<a, b, c, d>>;

D[Vector(%id = 20336480)](f) = Matrix(%id = 22240864)*Matrix(%id = 22418068)

The matrix whose rows are the gradients of the components of a vector function is known as the Jacobian.

Example 1.1

Find the derivative of    F(x,y) = [x, y, sin(x)+cos(y)] , at the point X  :=  [2, 2], in the direction, v = [1.5, 1].

 

>    restart: with(LinearAlgebra): with(VectorCalculus):with(plots):

>    F := (x, y) -><x, y, sin(x) + cos(y)>:

>    F(x, y);

Vector(%id = 17463764)

>    v := <1.5, 1>;

v := Vector(%id = 17708404)

>    X := <x, y> + t * v;

X := Vector(%id = 18112824)

>    delta := (F(X[1], X[2]) - F(x, y))/t;

delta := Vector(%id = 18182708)

>    dF := limit(delta, t = 0);

dF := Vector(%id = 18196352)

>    dF := evalf(subs({x = 2, y = 2}, dF));

dF := Vector(%id = 18367612)

Jacobian

>    r := [x, y, z]:  J1 := Jacobian(F(x, y), r);

J1 := Matrix(%id = 18632180)

>    J2 := evalf(subs({x = 2, y = 2}, J1));

J2 := Matrix(%id = 17085340)

Note that we needed to define all our vectors as three dimensional. Now we take the product of this matrix with v.

>    dF := J2.<1.5, 1, 0>;

dF := Vector(%id = 18699412)

We obtain the same result as with the definition.

For functions f : R^n  -> R  , Maple provides the DirectionalDiff  function.

DirectionalDiff

>    g := (x, y) ->sin(x) + cos(y):

>    g(x, y);

sin(x)+cos(y)

>    dg := DirectionalDiff(g(x, y), <1.5, 1, 0>, [x, y, z]);

dg := .8320502942*cos(x)-.5547001961*sin(y)

>    dg := evalf(subs({x = 2, y = 2}, dg));

dg := -.8506425587

Note that this differs from the z component of dF . This is because the Maple function DirectionalDiff uses the normalized  vector v/abs(v) , in place of v .

>    sqrt(1.5^2 + 1^2) * dg;

-1.533517681

In the same manner as in single variable calculus we write the equation for the tangent line to the surface at point X , with slope dF .  That is, we write the vector equation of a line through F(2, 2) and parallel to dF .  

ScalarMultiply

>    dF;

Vector(%id = 18699412)

>    F(2, 2);

Vector(%id = 17312908)

Tangent vector T

>    T  :=  F(2, 2)  +  ScalarMultiply(dF, s);

T := Vector(%id = 18923152)

Now we plot the surface, the direction vector, v , and the tangent vector, T.  First the surface:

>    P1  :=  plot3d(F(x, y), x = 1..4, y = 1..4, color = pink, style = wireframe, axes = framed):

Next the tangent vector, T  at the point F(2, 2).

>    P2  :=  spacecurve([T[1], T[2], T[3]], s =  - 0.5..1, color = red, thickness = 3):

Now the vector v  translated to the point F(2, 2).

>    v1  :=  F(2, 2) + s.<1.5, 1, 0>;

v1 := Vector(%id = 17250720)+s.Vector(%id = 17768120)

 

The ScalarMultiply  function is necessary when dealing with vectors written out as above. If the vector is defined as a list, then a simple s * v  will do.

>    P3 := spacecurve([v1[1], v1[2], v1[3]], s =  - 2..2, color = black, thickness = 3):

>    display(P1, P2, P3, axes = framed, labels = [x, y, z], scaling = constrained);

[Maple Plot]

 If the plot is rotated so that we are looking straight down on the x - y plane, we can see that the direction vector and the tangent vector are lined up with each other.  Also notice that the x and y ranges having been defined as equal the grid is square as well as rectilinear.
Suppose we complicate things just a bit.

Example 1.2

Define a function, G ( x, y, z )  =   [ x, y^2 , sin( x ) + cos( y^2 )] ,  keeping  everything the same except for the change from y to y^2 .

>    restart:with(plots): with(LinearAlgebra): with(VectorCalculus):

>    G := (x, y) -><x, y^2, sin(x) + cos(y)>:

>    G(x, y);

Vector(%id = 19221488)

>    v := <1.5, 1, 0>: r := [x, y, z]:

>    delta[G] := (G(x + t * v[1], y + t * v[2]) - G(x, y))/t;

delta[G] := Vector(%id = 19557308)

>    dG := limit(delta[G], t = 0);

dG := Vector(%id = 19561588)

>    dG := evalf(subs({x = 2, y = 2}, dG));

dG := Vector(%id = 19810184)

Write the equation for the tangent line.

>    T := G(2, 2) + ScalarMultiply(dG, s);

T := Vector(%id = 19246236)

Plot v , the tangent line and the surface.

>    P1 := plot3d(G(x, y), x = 1..4, y = 1..4, color = pink, style = wireframe):

>    P2 := spacecurve([T[1], T[2], T[3]], s =  - 0.5..1, color = red, thickness = 3):

>    v1 := G(2, 2) + ScalarMultiply(v, s);

v1 := Vector(%id = 20456104)

>    P3 := spacecurve([v1[1], v1[2], v1[3]], s =  - 2..2, color = black, thickness = 3):

>    display(P1, P2, P3, axes = framed, labels = [x, y, z]);

[Maple Plot]

This time, when we rotate the plot as before we find that the direction vector is not lined up with the tangent. The projection onto the x - y plane is definitely not square and the divisions graduate in size.

What has actually happened here is that we have effected a non - linear coordinate transformation. H :[ x, y ] ->[x, y^2 ]    This can be demonstrated very neatly in Maple. Remember that if K and H are maps on appropriately dimensioned spaces, the chain rule yields:   D ( K o H ) = (( DK ) o H )( DH )

>    restart:with(plots): with(LinearAlgebra):with(VectorCalculus):

Warning, the name changecoords has been redefined

Warning, the names CrossProduct and DotProduct have been rebound

Warning, the assigned names <, > and <|> now have a global binding

Warning, these protected names have been redefined and unprotected:  * ,  + , ., Vector, diff, int, limit, series

>    H := (x, y, z) ->(x, y^2, z);       # The coordinate change

H := proc (x, y, z) options operator, arrow; x, y^2, z end proc

>    K := (x, y, z) -><x|y|sin(x) + cos(y)>: # The function from example 1.1                                      

>    K(x, y, z);

Vector(%id = 17228716)

>    G := K@H; # Function composition

G := `@`(K,H)

>    G(x, y, z);

Vector(%id = 3105812)

>    r := [x, y, z]: J1 := Jacobian([H(x, y, z)], r);

J1 := Matrix(%id = 17416636)

>    k := K(x, y, z);

k := Vector(%id = 17231036)

>    J2 := Jacobian(k, r);

J2 := Matrix(%id = 17476180)

>    J2 := subs(y = y^2, J2); #compose DK with H

J2 := Matrix(%id = 17480832)

>    J2.J1;

Matrix(%id = 17586884)

And now, directly with G, confirming the correctness of the chain rule formula.

>    g := G(x, y, z);

g := Vector(%id = 2488656)

>    J3 := Jacobian(g, r);

J3 := Matrix(%id = 17579904)

It is the non - linear coordinate change, H,  that is responsible for the non - alignment of the direction vector and the tangent.  If the directional derivative happens to be in the direction of one of the coordinate vectors, say the y coordinate.

           

>    DirectionalDiff(f(w, x, y, z), <0, 0, 1, 0>, [w, x, y, z]);

diff(f(w,x,y,z),y)

This is the partial derivative of F with respect to y.  From this we see that the partial derivatives are actually directional derivatives in the direction of the coordinate basis vectors. The gradient is the vector whose components are the coordinate derivatives.

Practice

1. Find the derivative of the following functions in the direction of v at the point
indicated. Use both the definition and the Jacobian.

a.   f(x,y) = [x^2+y^2, x^2-y^2, x*y]    v  = [1, 1]  p = (2, 2)

b.   f(x,y) = [exp(-x+y), exp(x+y), x+y]       v  = [.25, .05]  p = (1, 2)

c.   f(x,y) = ln(x^2+y^2)   v  = [2.5.2.0]  p = (4, 5)

d.    f(x,y) = sin(x+y)+sin(x-y)     v  = [1, 2]   p = (2, 4)