Plotting Vector Fields
Worksheet by Mike May, S.J.- maymk@slu.edu
> restart;
Overview
In Math courses up through Calculus II, we studied functions where elements of both the domain (input values) and the range (output values) are numbers. In the firsct half of this course we have looked at functions that take vectors to numbers. In the last chapter we looked at parameterizations of curves (taking a number to a vector) and surfaces (taking a vector to a vector with a different number of coordinates). In those case we tended to graph just the output rather than the input and output together.
We are now ready to look at functions that take vectors to vectors of the same dimension. The standard example of this are functions that take exery point to a force or velocity at the same point. We can plot these vector fields with the fieldplot command in the plots package.
> with(plots);
Warning, the name changecoords has been redefined
Vector Fields in 2 dimensions
Whenever we look at a new command in Maple it is probably a good idea to look at the help page for it.
> ?fieldplot
We are ready to plot a simple vector field.
> fieldplot([-y,x],x=-3..3, y=-3..3, arrows=thick);
Notice that the plot reduces the scale of the arrows so that we do not get two much overlap. We can control the number of arrows plotted by using the grid option. (The default grid is [20, 20].) You may also want to box the axes to get them from under the arrows.
> fieldplot([-y,x],x=-3..3, y=-3..3, arrows=thick, grid=[3,3]);
Notice that Maple is centering the arrows over the input point rather than starting them at the point. Be sure to correct for this if you use fieldplot on a test or quiz.
Exercise:s
1) Plot the vector fields given by the formulas below. Exercises 2, 4, 5, and 7 from Section 17.1.)
(a) F(x, y) = 2i + 3j.
>
(b) F(x, y) = 2xi +xj.
(c) F(x, y) = [x + y, x- y].
(d) F(r) = r.
2) Use fieldplot to verify that you have found the correct formulas in 2 for the fields described below.
(a) All vectors are vertical. They proportionally increase in length, always pointing away from the y-axis.
(b) All vectors point radially our from the origin. The magnitude of any vector is proportional to the distance of the starting point from the origin.
(c) All vectors are of length 1 and point radially out from the origin.
(d) The vectors form a counterclockwise swirl growing as you move out from the origin.
(e) The vectors form a clockwise swirl. All vectors are of length 1.
Gradient fields in 2 dimensions
The most common kind of vector field we will be interested in plotting are vector fields that are produced as the gradients of a multivariable function. We can either computer the gradient and then plot it or use the gradplot command. (Maple has a special command for plotting gradient fields.)
> ?gradplot
> f := (x, y) -> x^2 + 2*y^2; gradf := [diff(f(x,y),x), diff(f(x,y),y)]; fieldplot(gradf, x=-3..3, y=-3..3, arrows=thick); gradplot(f(x,y), x=-3..3, y=-3..3, arrows=thick);
You should recall that the gradient vector is always perpendicular to the contours of the function. It is worthwhile to put a contourplot together with the gradplot.
(Note that we are putting 2 plots together with the display command. When creating the plots we use colons rather than semicolons.)
> f := (x, y) -> x^2 + 2*y^2; gradf := gradplot(f(x,y), x=-3..3, y=-3..3, arrows=thick, grid=[10, 10]): contourf := contourplot(f(x,y), x=-3..3, y=-3..3): display({gradf, contourf});
Exercises:
3) Plot the gradient field for the function x^2-y^3 over the window [-10, 10]x[-10, 10].
4) Plot the gradient field of x^2 - 2x + y^2 +4y - 8 togethr with a contour map of the same function on the region [-10, 10]x[-10, 10].
Vector and Gradient Fields in 3 dimensions
When we go to 3 dimensions, the theory remains the same. We simply change the commands to the ones appropriate for 3 dimenstions. The commands fieldplot and gradplot become fieldplot3d and gradplot3d.
To illoustrate we plot the gradient field of x^2 + y^2 + z^2 both as a vector field that we have computed and also as gradplot.
> fieldplot3d([2*x, 2*y, 2*x], x=-5..5, y=-5..5, z=-5..5, arrows=THICK, axes=boxed);
> gradplot3d(x^2 + y^2 + z^2, x=-5..5, y=-5..5, z=-5..5, arrows=THICK, axes=boxed);
5) Graph the following vector fields. (Problems 7 and 8 from section 18.2.) Descibe the vector field in words.
(a) F(x, y, z ) = xi + 2zyj + xk.
(b) F(x, y, z) = [x^3, y^2, z].
6) Plot the gradient fields of the following functions.
(a) f(x, y, z) = -x^2 - y^2 + z^2.
(b) f(x, y, z) = (x - 1)^2 + y^2 + z^2.
If we want to plot the gradient field together with the level surface of a function things get a little more complicated. The display command is replced by the display3d command. Unfortuneately, the contourplot3d does not give level surfaces. Instead we need to use implicitplot3d. Maple warns that implicitplot3d is memory intensive.
> ?implicitplot3d
> g := (x, y, z) -> x^2 + 2*y^2 - (3 + sin(z))^2; gradg := gradplot3d( g(x, y, z), x=-5..5, y=-5..5, z=-5..5, axes=boxed, arrows=THICK, grid=[5, 5, 5]): surfg := implicitplot3d(g(x, y, z), x=-5..5, y=-5..5, z=-5..5, color=green, style = patch): display3d({gradg, surfg});