Lab 7: Vector Fields

by Paul Brown, Heidi Burgiel, and Marc Culler
Copyright © 1998 Paul Brown, Heidi Burgiel, Marc Culler

Introduction

The purpose of this lab is to impart a graphical understanding of the idea of a conservative vector field. You will learn how to use Maple to draw pictures of vector fields and you will learn how to recognize a gradient vector field visually.

Vector Fields

A vector field is given by a function F that assigns a vector in the plane (or in n-dimensional space) to each point in the plane (or in n-dimensional space). In other words, F(x,y) specifies a direction and magnitude at each point (x,y). Vector fields are commonly used to model natural and physical phenomena such as wind and water velocity, magnetic fields, electric fields, or gravitational forces. Of course, one example of a vector field with with you are already familiar is the gradient of a function.
 

Given a vector field F on the plane, we can visualize it by imagining that attached to a point (x,y) in the plane is an arrow representing the vector F(x,y). We can write F as two functions,F=<F1,F2>, in which case:
 
 

F(x,y) = <F1(x,y) , F2(x,y) >,

where F1 and F2 are scalar functions.

Maple uses square brackets for vectors, e.g., [-1,1,3], instead of the parentheses or angled brackets that you may be used to.

> v:=[-1,1,3];u:=[5,-2,4];

[Maple Math]

[Maple Math]

Maple can perform many of the standard operations on vectors, so long as you're willing to load the linalg package and go through a few contortions.

> with(linalg):

For instance, Maple can add vectors:

> add(u,v);

[Maple Math]

(If you're using a Maple VR5, you can just use "+".)

Maple can do scalar multiplication:

> scalarmul(u,3);

[Maple Math]

Maple can do dot products:

> dotprod(u,v);

[Maple Math]

And Maple can do cross products:

> crossprod(u,v);

[Maple Math]

Here is how to enter a vector field in Maple. First, define the two scalar functions which are the coordinates of the vector field:

> F1:= (x,y) -> x^2+y^2;

[Maple Math]

> F2:= (x,y) -> -x*y;

[Maple Math]

Next, we combine the two scalar functions to create a single vector to vector function. Note the square brackets!

> F:= (x,y) -> [F1(x,y),F2(x,y)];

[Maple Math]

> F(x,y);

[Maple Math]

Alternatively, we could have simply entered the vector field with a single line:

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

[Maple Math]

Just as with other functions defined in Maple, we can simply plug values into F to see what the value of the vector field at a point is:

> F(1,4);

[Maple Math]

Plotting Vector Fields with Maple

Maple's fieldplot() command (part of the plots package) plots vector fields in much the same way as plot3d plots surfaces. The arguments to fieldplot consist of a vector field and the ranges of x and y values which describe the rectangle in which the vector field will be plotted. The specified rectangle is divided up into a grid (20 x 20 by default), and an arrow representing the value of F is drawn at each grid point. The vector field really includes an arrow for every point in the plane, but Maple only draws the ones on the grid points; it's up to your imagination to fill in what lies between. (If Maple were to plot all of the arrows, you would just see a solid black plane.)

Here is a basic example, one to which we will return later in the lab:

> with(plots):

> F:= (x,y) -> [-y,x];
fieldplot(F(x,y),x=-1..1,y=-1..1);

[Maple Math]

[Maple Plot]

The plot above shows the default arrows style ("arrows=THIN"), but you can also use "arrows=SLIM" or "arrows=THICK" depending on which you find easiest to read. These other arrow styles appear in example pictures below.

Just as when plotting surfaces, it is important to choose your domain rectangle carefully.

For instance, with the vector field below, a wide view shows us many circular arrangements of arrows:

> fieldplot( [-sin(y),cos(x)],x=-20..0,y=0..20, arrows=SLIM);

[Maple Plot]

But choosing a smaller range gives us more detail:

> fieldplot( [-sin(y),cos(x)],x=-5..0,y=0..5, arrows=THICK);

[Maple Plot]

Question 1:Make a plot of the vector field F(x,y)=<-y,x>. Where do the vectors of the vector field F(x,y) = (-y,x) have the least magnitude? Why? In what direction (positive or negative x/positive or negative y) do the vectors in the first quadrant (where x and y are both positive) point? Why?

If you'd like to be reminded about the relationship between contours and gradient vector fields, follow the link below.

A digression on gradients, contour lines, and vector fields.

From Vector Fields to Contours?
 

As mentioned above, one very important type of vector field is the gradient of a function f(x,y). Taking the gradient of a function of two or more variables is much like taking the derivative of a function of one variable. So, as in one-variable calculus, it is natural to try to find "antiderivatives" for the vector fields. That is, we will start with a vector field Fand try to find a function f(x,y) such that F is the gradient of f. However, there is one way in which the two-variable situation is very different from the one-variable situation: Any continuous function of one variable has an antiderivative, but most vector fields are not gradient vector fields.

Vector fields are divided into two classes, conservative and non-conservative. All of the vector fields with "anti-derivatives" fall into the conservative category. Just a little further on, we will define what it means for a vector field to be conservative, but first, we'll look at some examples of vector fields that are not gradient fields.

The Mixed Partials Test

This section describes an easy but non-geometric way to test a vector field to see whether or not it is a gradient vector field.

Suppose that our vector field F=<F1,F2> is the gradient of a hypothetical function f. Then, F1 is the x-partial of f and F2 is the y-partial of f. So, if f is differentiable, we should have that the xy-derivative and the yx-derivative are equal, i.e., that the x-derivative of F2 and the y-derivative of F1 are equal.

Recall that in Maple, F(x,y)[1] is the x-component of F, i.e., x-derivative of the hypothetical f. Also, F(x,y)[2] is the y-component of the hypothetical f. So if Fis a gradient, the x-derivative of F(x,y)[2] and the y-derivative of F(x,y)[1] must be equal.

Let's choose a vector field (more or less) at random and use Maple to give this a try:

> F := (x,y) -> [y^3-x^2+5, y-x^3-5];

[Maple Math]

> f_xy=diff(F(x,y)[1],y);

[Maple Math]

> f_yx=diff(F(x,y)[2],x);

[Maple Math]

The mixed partials don't match, so F is not a gradient vector field.

Digression on indirect reasoning.

In the following example, we will use an indirect argument to show that there is a vector field which is not the gradient of a function.

Reconsider the first vector field we plotted above:

> fieldplot( [-y,x], x=-1..1, y=-1..1,arrows=THICK );

[Maple Plot]

Suppose that there is some function f that has as its gradient the vector field above. (This is the supposition that we are going to attempt to show is false.)

Recall that the gradient vector always points in the "uphill" direction. Consider walking around the origin on a counterclockwise (with the arrows) circular path. Because the path is in the uphill direction for its entire length, we would be able to walk in a circle, going uphill the entire way. Thus, even though we end up at exactly the same spot, we would be at a higher altitude! This is impossible. (Although it does appear to happen in the fantastic world of MC Escher's famous trompe l'oeil etching "Ascending and Descending".) Here in the real world we can conclude by contradiction that there is no function that gives rise to the vector field above.

The Cat Petting Theorem

The example at the end of the previous section can be generalized to obtain the following Theorem:

THEOREM: Let F be a vector field and let c be a smooth simple closed curve. If it is the case that the dot product of F and c'(t) is positive (i.e., in layman's terms, the vector field and the tangent to the curve point in similar directions) for all t in the parameterization of c, then the vector field F is not the gradient of a function f. (See margin note in Stewart, p. 912.)

You will soon learn the Fundamental Theorem of Calculus for vector fields in class, and we will state it below. The Cat Petting Theorem is a direct corollary.

Line Integrals and Why the Cat Petting Theorem is True

In order to understand the statement of the Fundamental Theorem of Calculus for vector fields, we need a notion of what it means to integrate along a path.

Suppose we have a function g of one variable. Then, if h is an antiderivative for g and we integrate from a to b, we end up with the value h(b)-h(a) as the answer. We can think of this as starting at the height h(a) and then "adding up" the infinitesimal height changes h'(t)dt=g(t)dt as t ranges from a to b; we end up at h(b), and the total distance travelled is h(b)-h(a). Removing the quotes from "adding up" requires carefully defining the integral, and this is the Fundamental Theorem of Calculus.

To generalize this to two or more variables, start with a function f and a path c from c(a)=p1to c(b)=p2. We begin at the height f(p1), and then as we take infinitesimal steps along the path c, the infintesimal steps change our altitude by the directional derivative of f along the curve c. (Recall that the directional derivative of f along a curve c is the gradient of f dotted with c'.) In the end, "adding up" these infinitesimal changes, we arrive at the height f(p2), and the total change in height is f(p2)-f(p1).

Unraveling the definition of the directional derivative, we are integrating the dot product of the gradient of fwith the tangent vector to cfor the values of t from a to b. Now, if we only have the gradient Fof f, we can still make the same computation without using fat all, and this is how we extend this definition to integrate any vector field F along a path c: We simply "add up" all of the dot products of F with the tangent vectors to the curve c, and result is the integral of F along c. To distinguish this sort of integral from the one-variable integral, it is generally called a line integral, even though the curve c may not be a straight line...

The Fundamental Theorem of Calculus for Vector Fields

The Fundamental Theorem of Calculus for vector fields says that the line integral of the gradient of falong a path is the difference of the values of fat the endpoints.

The Cat Petting Theorem is true because if F were the gradient of some function f, then f(c(a)) would differ from f(c(b)) by the integral of F along c. Since c in the case of the Cat Petting Theorem is closed, it begins and ends at the same point, and the difference in altitude (and thus the line integral) is zero. However, the directional derivative of f, i.e., the dot product of F and c', is positive at every point of c by the assumption that F and c' form an angle of less than ninety degrees at all times!! This fact - that we are constantly gaining altitude - contradicts the Fundamental Theorem of Calculus for vector fields, which says that if F were a gradient vector field, we should return to the same place and get a zero for the line integral. Thus, we conclude that F is not a gradient vector field.

Now that we have at least a heuristic handle on line integrals, we can define what it means for a vector field to be conservative:

Definition of Conservative Vector Field

A vector field F is conservative if the line integral of F around every closed path is zero.

The Fundamental Theorem of Calculus for vector fields can be used to prove that only gradient vector fields are conservative; you will learn that all non-gradient vector fields are non-conservative.

We can use the Cat Petting Theorem to visually identify vector fields which are not the gradients of functions. Recall that (most) cats don't like having their hair rubbed the wrong way. To paraphrase the Theorem, if you think of the vectors in a vector field as being hairs on a cat, and you can pet it in a circle without annoying the cat, then the cat is non-conservative.

Take a look at the following vector field:

> F := (x,y) -> [y^3-x^2+5, y-x^3-5];
fieldplot(F(x,y),x=-3..1,y=-2..2,grid=[15,15], arrows=THICK);

[Maple Math]

[Maple Plot]

Now, let's imagine traversing counterclockwise a circle of radius 2 centered at (-1,0):

> display({
fieldplot(F(x,y),x=-3..1,y=-2..2,grid=[15,15],arrows=SLIM),
implicitplot((x+1)^2+y^2=4,x=-3..1,y=-2..2,color=RED)});

[Maple Plot]

You'll have to look very carefully at the plot, but the arrows always form an angle of less than 90 degrees with the tangent to the circle, so the hypotheses of the Cat Petting Theorem are satisfied and the vector field is not the gradient of any function.

Exercise 1

The fact that the vectors above point with the direction of the curve means that the line integral around the curve above will be a positive number. What if we were to traverse the curve in the opposite direciton? (Hint: Think about what happens when you reverse the endpoints of a definite integral of a function of one variable.)

Using Maple to Find Antiderivatives for Vector Fields

Maple's DEtools package contains a line integral command called line_int that we can use to find the function of which a vector field is the gradient, provided that the field is actually a gradient vector field. The first argument is the vector field, the second argument is a list of variables to use, and the third argument should always be "check". (If you do not use the "check" option, you can receive nonsense answers!)

If we feed line_int a gradient vector field, it will return a function that it is the gradient of:

> line_int([x^2+y^2,2*x*y],[x,y],check);

[Maple Math]

But if we feed a vector field that is not a gradient vector field, it returns an error. Here is what happens if we feed in the vector field F from above:

> with(DEtools):
line_int(F(x,y),[x,y],check);

Error, (in ODEtools/line_int) The given first argument, [y^3-x^2+5, y-x^3-5], is not a total derivative
How do you think Maple makes this check? (Hint: You saw a test up above that would work...)

Conclusion

We have now seen several different ways to decide on whether a vector field F is conservative:

1)Look for a simple, closed curve where the vector field and the tangent to the curve point always point in similar directions (The Cat Petting Theorem);
2)Compute partials derivatives of the component functions of the vector field; and
3)Use Maple's line_int command.

Exercise 2

For each of the following vector fields, make a picture using Maple's fieldplot command and then decide whether or not the field is conservative by attempting to find a closed curve with non-zero line integral and apply the Cat Petting Theorem. If you think the field is conservative, then use Maple's line_int command to find a function. (Don't forget to load the plots and DEtools packages.)

a) [x^2+y^2,x*y]

b) [-x*y,-y*x]

c) [sin(x),cos(y)]

d) [x^2-2*y,y^2-2*x]

e) [sin(x)*cos(y),cos(x)*sin(y)]