L2-VectorDiff.mws

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


Lesson 2: Vector Derivatives: grad, div, curl, laplacian

Topics : Gradient, divergence, curl are illustrated and graphically interpreted. Laplacian defined.
Maple commands introduced:
Gradient, Divergence, Curl, Laplacian, fieldplot, evalVF

Gradient

Example 2.1

Let   f = sin(x)-log(sin(y)) .  Compute and plot grad w.   We will plot level sets w^(-1) ( k ) , for k from 0.1 to 1.0.

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

>    f := sin(x) - log(sin(y));

f := sin(x)-ln(sin(y))

Plotting ten level sets of f(x, y)

>    S := seq(f - 1/k = 0, k = 1..10):

>    P1 := implicitplot({S}, x = 3..3.5, y = 0..1.5, numpoints = 1000):

>    display(P1, scaling = constrained);

[Maple Plot]

The value of k represented by these curves increases from right to left.

Now compute the gradient at x = 3.3 on the level set of f(x,y) = 1/10

>    gf := Gradient(f - 1/10, [x, y]);

gf := Vector(%id = 19937484)

>    Y := fsolve(subs(x = 3.3, f - 1/10), y);

Y := .8832282346

>    G := evalVF(gf, <3.3, Y>);

G := Vector(%id = 20487772)

evalVF

Now we draw and plot a line through the point [3.3, .8832282346], and parallel to G.

>    N := <3.3, Y> + s * G;

N := Vector(%id = 20982668)

>    P2 := plot([N[1], N[2], s =  - 0.2..0.3], thickness = 2, color = black):

>    display(P1, P2, scaling = constrained);

[Maple Plot]

The gradient vector appears to pierce each of the level sets orthogonally to its tangent.  If this is so, then the gradient vector represents  the shortest distance between successive level sets and, therefore, the most rapid change in the value of w. This is, in fact, true of any function in any dimension.

We consider a surface of arbitrary dimension represented by a level set of a map:  F: R^n  -> R  ;   f ( x[1] ... x[n] )  =   K , and a curve, gamma(t) = [x[1](t) .. x[n](t)]     , imbedded in the surface, and passing through a point,    p = x[1](t[0]) .. x[n](t[0])  .      F(gamma(t)) = f(x[1](t) .. x[n](t))  = K    Taking the gradient:   grad(F(gamma(t)))   =  grad F( gamma(t)   gamma '( t )  =  0.  Since [Maple OLE 2.0 Object]  is the principal part of the tangent vector to [Maple OLE 2.0 Object] ,  grad F ( gamma ( t ))  is orthogonal to the tangent to the curve gamma(t)  at p.  But every tangent to the surface at p, is the tangent to a curve,  (existence theorem for solution of first order differential equations) so  grad F ( gamma ( t ))  is orthogonal to the tangent plane at p.  The gradient vector represents the direction and magnitude of the greatest change in F, at the point where it is evaluated.

This can be illustrated easily in three dimensions.

Example 2.2

Let   [Maple OLE 2.0 Object]  .  Compute and plot the gradient vector.
Define an implicit function of (x, y, z) for various values of K.

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

>    F := K ->z - x^2 + y^2 + 4 * x * y - K:

>    v := [x, y, z]: gradF := Gradient(F(0), v);

gradF := Vector(%id = 17444312)

We could equally well have taken any value of K. 0 happens to be convenient  because it gives simple integer values for the components of the gradient.

>    p := <1, 1,  - 4>:

>    gF[1, 1,  - 4] := evalVF(gradF, p);  #The gradient vector at (1, 1,  - 4)
                                         

gF[1,1,-4] := Vector(%id = 17800388)

>    G := p + s * gF[1, 1,  - 4];

G := Vector(%id = 17914848)

>    P1 := spacecurve(evalm(G), s =  - .2..0.25, color = black, thickness = 2, axes = boxed):

>    S := seq(implicitplot3d(F(5 * k), x = 0..2, y = 0..2,
z =  - 5.. - 2, style = wireframe, color = pink, grid  =  [12, 12, 12]), k = 0..3):

>    display(S, P1, scaling = constrained, orientation = [ - 20, 65]);

[Maple Plot]

The gradient vector appears to be orthogonal to each of the level sets.
                    

Without presenting any mathematical justification (although ample justification exists), we will operate with the gradient vector operator as if it were an ordinary vector; we will take both the dot product and the  crossproduct of  del with ordinary vectors and with itself.  

 The curl of a vector V is defined by: curl(V) =  del x V

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

There are two defined forms of the curl in Maple. One, spelled with a small "c" is in the linalg  package and operates on vectors; the other, spelled with a capital "C" is in the VectorCalculus  package and operates on vector fields.

curl

Curl

>    V := VectorField(<v[1](x, y, z), v[2](x, y, z), v[3](x, y, z)>, 'cartesian'[x, y, z]);

V := Vector(%id = 17579320)

>    Curl(V);

Vector(%id = 18797964)

>    V1 := [v[1](x, y, z), v[2](x, y, z), v[3](x, y, z)];r := [x, y, z]:

V1 := [v[1](x,y,z), v[2](x,y,z), v[3](x,y,z)]

>    curl(V1, r);

vector([diff(v[3](x,y,z),y)-diff(v[2](x,y,z),z), diff(v[1](x,y,z),z)-diff(v[3](x,y,z),x), diff(v[2](x,y,z),x)-diff(v[1](x,y,z),y)])

To have an idea of what this means, consider a vector field, that is, a function that assigns a vector to each point in the domain.

Example 2.3

 Let   F(x,y) = [x^2*y, y^2*x, x^2-y^2]       Take the curl of this vector field and fieldplot both.

fieldplot    fieldplot3d

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

>    F := (x, y) -><x^2 * y, y^2 * x, x^2 - y^2>:

>    F(x, y);

Vector(%id = 20491132)

>    curl_F := curl(F(x, y), [x, y, z]);

curl_F := vector([-2*y, -2*x, y^2-x^2])

>    f1 := fieldplot3d(F(x, y), x =  - 10..10, y =  - 10..10, z =
 - 10..10, axes = framed, color = red, arrows = THICK, grid = [3, 3, 3]):

>    f2 := fieldplot3d(curl_F, x =  - 10..10, y =  - 10..10,
z =  - 10..10, axes = framed, color = black, arrows = THICK, grid = [3, 3, 3]):

>    display(f1, f2);

[Maple Plot]

If the original vector field F, (thick arrows) represents the velocity of fluid flow in a container, then curl F (the thinner arrows) is the torque exerted by the fluid, both in magnitude and direction, (determined by the right hand rule).  If  any group of thick vectors is rotated into an adjacent group and the fingers of the right hand curled in the direction of rotation, the thumb of the right hand will point in the direction of the thinner vectors (the torque) situated between the two groups.

Now formally defining the vector field.

>    FF := VectorField(F(x, y), 'cartesian'[x, y, z]);

FF := Vector(%id = 17224272)

>    CFF := Curl(FF);

CFF := Vector(%id = 17224392)

>    P3 := fieldplot3d(FF, x =  - 10..10, y =  - 10..10, z =
 - 10..10, axes = framed, color = red, arrows = THICK, grid = [3, 3, 3]):

>    P4 := fieldplot3d(CFF, x =  - 10..10, y =  - 10..10,
z =  - 10..10, axes = framed, color = black, arrows = THICK, grid = [3, 3, 3]):

>    display(P3, P4);

[Maple Plot]

The alternative to Curl .

>    Del &x FF;

Vector(%id = 17693120)

Note that, because of the equality of mixed partial derivatives,  del x del = 0.

>    del := <d/dx, d/dy, d/dz>;

del := Vector(%id = 17877760)

>    del &x del;

Vector(%id = 17705356)

Since we are considering del as a vector we may also take the dot product of del with a vector, V.  This is known as the divergence of V.  Again there are two definitions, Divergence and diverge in the VectorCalculus and linalg packages, operating on vector fields and vectors respectively.

Divergence

diverge

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

>    V := (x, y, z) -> <v[1](x, y, z), v[2](x, y, z), v[3](x, y, z)>:

>    VV := VectorField(V(x, y, z), 'cartesian'[x, y, z]);

VV := Vector(%id = 3095224)

>    Divergence(VV);

diff(v[1](x,y,z),x)+diff(v[2](x,y,z),y)+diff(v[3](x,y,z),z)

>    V1 := [v[1](x, y, z), v[2](x, y, z), v[3](x, y, z)];

V1 := [v[1](x,y,z), v[2](x,y,z), v[3](x,y,z)]

>    diverge(V1, [x, y, z]);

diff(v[1](x,y,z),x)+diff(v[2](x,y,z),y)+diff(v[3](x,y,z),z)

To have a picture of what this might mean, suppose we consider F as the velocity field of some gas.  That is, F is a vector field representing the velocity of the gas particles (assumed to be uniform) at each point.

Example 2.4

Find and plot the divergence of [Maple OLE 2.0 Object] .

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

>    F := (x, y) ->[x^2 * y, y^2 * x, x^2 - y^2]:

>    FF := VectorField(<F(x, y)>, 'cartesian'[x, y, z]);

FF := Vector(%id = 19218624)

>    Div_F := Divergence(FF);

Div_F := 4*x*y

The divergence is a scalar quantity.  If we construct a vector parametrized by x and y with div_F as the z coordinate, we will obtain a surface representing div F  at each point in the x - y plane.    

>    G := <x, y, 4 * x * y>;

G := Vector(%id = 19219144)

We now plot G together with F.

>    P1 := plot3d(G, x =  - 2..2, y =  - 2..2, axes = framed, color = blue, style = wireframe):

>    P2 := fieldplot3d(F(x, y), x =  - 2..2, y =  - 2..2, z =
 - 2..2, axes = framed, color = pink, color = red, arrows = THICK, grid = [5, 5, 2]):

>    display(P1, P2);

[Maple Plot]

 The surface div V represents the flux of gas out of a unit cube.  Observe that where the arrows point inward, the flux is negative,  gas particles accumulate in the cube; the density of the gas rises.  Where the arrows point outward, the flux is positive, the density of gas particles in the cube is diminishing. div F therefore measures the change in density of gas in the cube.  

div(grad) is defined and is an operator of the greatest importance: the Laplacian.

Maple does not have a way to input partial differential operators.

>    del := <d/dx, d/dy, d/dz>;

del := Vector(%id = 19598188)

>    Lap := del.del;

Lap := d^2/dx^2+d^2/dy^2+d^2/dz^2

The Laplacian function, is however, defined in the linalg  package and the VectorCalculus  package.

laplacian

Laplacian

Grad, curl and div figure largely in physical applications and will all be looked at more closely as we proceed.

Practice

1. Plot each of the following vector fields together with its curl.

a.   F(x,y) = [x+y, x-y, x*y]

b. F(x,y) = [-x/(x^2+y^2), y/(x^2+y^2), 1/(x^2+y^2)]

c. F(x,y) = [sin(x+y), cos(x+y), x+y]