Plotting Vector FieldsWorksheet by Mike May, S.J. - maymk@slu.eduRevised by Russell Blyth - blythrd@slu.edurestart;OverviewIn math courses up through single variable calculus we study functions where elements of both the domain (input values) and the range (output values) are numbers. In the first half of multivariable calculus we have looked at functions that take vectors to numbers. Recently we looked at parameterizations of curves (functions taking numbers to vectors) and soon we will consider parametrizations of surfaces (functions taking vectors to vectors with a different number of coordinates). In these cases we tend 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 examples of this are functions that take every point to a force or velocity vector at the same point. We can plot these vector fields with the fieldplot command in the plots package.with(plots):Vector fields in two dimensionsWhenever we use a new command in Maple it is probably a good idea to look at the help page for it. Once the Help window opens, select fieldplot from the list.?fieldplotWe are ready to plot a simple vector field. At each point (x,y), this plot shows the vector field -yi + xj.fieldplot([-y,x],x=-3..3, y=-3..3, arrows=thick);Notice that the plot reduces the scale of the arrows of the vector field so that we do not get too 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.)Exercises1. Plot the vector fields given by the formulas below. (a) F(x, y) = 2i + 3j.(b) F(x, y) = 2xi +xj.(c) F(x, y) = [x + y, x- y].(d) F(r) = 2r (use the coords=polar option)2. Use fieldplot to verify that you have found a correct formula for the fields described below.(a) All vectors are vertical. They proportionally increase in length, always pointing away from the x-axis.(b) All vectors point radially out 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 two dimensionsThe most common kind of vector fields we are interested in plotting are vector fields that are produced as the gradients of a multivariable function. We can either compute the gradient and then plot it, or use the gradplot command. (Maple has a special command for plotting gradient fields.)?gradplotf := (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 of a function is always perpendicular to the contours of the function. It is worthwhile to put a contourplot together with the gradplot. (Recall we put two plots together with the display command. When creating the plots we use colons rather than semicolons to terminate the commands to suppress the output of these commands.)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});Exercises3. 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 together with a contour map of the same function on the region [-10, 10]x[-10, 10].Vector and gradient fields in three dimensionsIn three dimensions the theory remains the same. We simply change the commands to the ones appropriate for three dimensions. The commands fieldplot and gradplot become fieldplot3d and gradplot3d.To illustrate, 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);Exercises5. Graph the following vector fields. 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 replaced by the display3d command. Unfortunately, the contourplot3d does not give level surfaces. Instead we need to use implicitplot3d. Maple warns that implicitplot3d is memory intensive. It makes little sense visually to plot more than one level surface at a time.?implicitplot3dg := (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=red, style = patchnogrid):
display3d({gradg, surfg});