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
:
->
, 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), g(w, x, y, z), h(w, x, y, z), k(w, x, y, z)>: |
| > | F(w, x, y, z); |
Let v be a direction along which we compute the derivative of F .
| > | v := <a, b, c, d>; |
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) = <<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>>; |
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]>; |
In this notation:
| > | D[v](f) = <<grad(f), grad(g), grad(h), grad(k)>> * <<a, b, c, d>>; |
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) -><x, y, sin(x) + cos(y)>: |
| > | F(x, y); |
| > | v := <1.5, 1>; |
| > | X := <x, y> + t * v; |
| > | delta := (F(X[1], X[2]) - 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[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>; |
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); |
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) -><x, y^2, sin(x) + cos(y)>: |
| > | G(x, y); |
| > | v := <1.5, 1, 0>: r := [x, y, z]: |
| > | delta[G] := (G(x + t * v[1], y + t * v[2]) - 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[1], T[2], T[3]], s = - 0.5..1, color = red, thickness = 3): |
| > | v1 := G(2, 2) + ScalarMultiply(v, s); |
| > | 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]); |
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) -><x|y|sin(x) + cos(y)>: # 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)