 Application Center - Maplesoft

# Calculus IV: Complete Set of Lessons

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

L1-DirectionalDiff.mws

Calculus IV with Maple
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 : -> , the directional derivative of f ( x )  in the direction v is defined as: > 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); Let v  be a direction along which we compute the derivative of F .

 > v := ; Let 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;  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);    This is conveniently written as a matrix equation.

 > D[v](f) = <, , , > * <>; 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  =  ; In this notation:

 > D[v](f) = <> * <>; 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 , at the point X  :=  [2, 2], in the direction, v = [1.5, 1].

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

 > F := (x, y) ->:

 > F(x, y); > v := <1.5, 1>; > X := + t * v; > delta := (F(X, X) - F(x, y))/t; > dF := limit(delta, t = 0); > dF := evalf(subs({x = 2, y = 2}, dF)); Jacobian

 > r := [x, y, z]:  J1 := Jacobian(F(x, y), r); > J2 := evalf(subs({x = 2, y = 2}, J1)); 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>; We obtain the same result as with the definition.

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

DirectionalDiff

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

 > g(x, y); > dg := DirectionalDiff(g(x, y), <1.5, 1, 0>, [x, y, z]); > dg := evalf(subs({x = 2, y = 2}, dg)); Note that this differs from the z component of dF . This is because the Maple function DirectionalDiff uses the normalized  vector , in place of v .

 > sqrt(1.5^2 + 1^2) * dg; 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; > F(2, 2); Tangent vector T

 > T  :=  F(2, 2)  +  ScalarMultiply(dF, s); 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, T, T], 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>; 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, v1, v1], s =  - 2..2, color = black, thickness = 3):

 > display(P1, P2, P3, axes = framed, labels = [x, y, z], scaling = constrained); 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, , sin( x ) + cos( )] ,  keeping  everything the same except for the change from y to .

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

 > G := (x, y) ->:

 > G(x, y); > v := <1.5, 1, 0>: r := [x, y, z]:

 > delta[G] := (G(x + t * v, y + t * v) - G(x, y))/t; > dG := limit(delta[G], t = 0); > dG := evalf(subs({x = 2, y = 2}, dG)); Write the equation for the tangent line.

 > T := G(2, 2) + ScalarMultiply(dG, s); 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, T, T], s =  - 0.5..1, color = red, thickness = 3):

 > v1 := G(2, 2) + ScalarMultiply(v, s); > P3 := spacecurve([v1, v1, v1], s =  - 2..2, color = black, thickness = 3):

 > display(P1, P2, P3, axes = framed, labels = [x, y, z]); 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, ]    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 > K := (x, y, z) ->: # The function from example 1.1

 > K(x, y, z); > G := K@H; # Function composition > G(x, y, z); > r := [x, y, z]: J1 := Jacobian([H(x, y, z)], r); > k := K(x, y, z); > J2 := Jacobian(k, r); > J2 := subs(y = y^2, J2); #compose DK with H > J2.J1; And now, directly with G, confirming the correctness of the chain rule formula.

 > g := G(x, y, z); > J3 := Jacobian(g, r); 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]); 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. v  = [1, 1]  p = (2, 2)

b. v  = [.25, .05]  p = (1, 2)

c. v  = [2.5.2.0]  p = (4, 5)

d. v  = [1, 2]   p = (2, 4)