\magnification=\magstep1
\centerline{Mathematics 41, section 1 -- Multivariable Calculus}
\centerline{Different Plotting Functions for $f(x,y)$ in Maple}
\centerline{September 29, 1999}
\bigskip
\noindent
{\it Background}
\bigskip
As we discussed in class on Monday, there are a number of ways to
generate graphics to represent the behavior of functions
$f(x,y)$ on domains $D \subset {\bf R}^2$.  In this document, we
summarize the Maple commands for producing each.  Three of these
(namely {\tt densityplot}, {\tt contourplot}, and {\tt contourplot3d}) 
are in the {\tt plots} package.  So it is best to start any worksheet where
you want to produce plots by loading that package with the 
command 
\medskip
\centerline{\tt with(plots):}
\bigskip
\noindent
{\it 1.  Density Plots}
\bigskip
The command for producing density plots is called 
{\tt densityplot}.  The format is
\medskip
\centerline{\tt densityplot(expression,xrange,yrange,options);}
\medskip
\noindent
For example, try the command 
\medskip
\centerline{\tt densityplot(x\^{}2 - y\^{}2, x=-3..3,y=-3..3);}
\medskip
\noindent
You will see a density plot, shown together with a default 25 $\times$ 25
grid on the rectangle $[-3,3] \times [-3,3]$.  

\bigskip
\noindent
{\bf Important Note:}  This command in Maple actually has a "known bug"!!
The light areas are supposed to represent {\it larger function
values}, and the dark areas are supposed to represent {\it smaller
function values}.  If you look carefully at your plot, you will see that the 
picture is ``backwards'' from what you would expect according to 
this information.  The function should larger positive values at points
on the $x$-axis and smaller, more negative values at points on 
the $y$-axis.  But the lightest parts of the density plot are 
near $y = \pm 3$.  What is wrong is that the $x$- and $y$-axis labels 
in the plot are reversed.  (D'oh!!)  You will need to take that into account 
in looking at Maple density plots (until this is fixed in a future version). 

\bigskip
\noindent
To change the default $25 \times 25$ grid to an $m \times n$ grid, 
you can include an option {\tt grid=[m,n]}.  Sometimes it is helpful
not to see the grid lines.  You can do that with an option
{\tt style = PATCHNOGRID}.  Try the modified command
\medskip
\centerline{\tt densityplot(x\^{}2 - y\^{}2, x=-3..3,y=-3..3, grid=[50,50],style=PATCHNOGRID);}
\medskip
\noindent
to see the effects of these options.
\bigskip
\noindent
{\bf Another Important Note:} Density plots with very ``fine'' grids
(big values for $m$, $n$) take up a lot of space.  If you have 
multiple density plots in a worksheet, you may want to save the worksheet
with the output removed (use the Remove Output option from the 
bottom of the Edit pulldown menu).  
\bigskip
\noindent
{\it 2. Contour Plots}
\bigskip
\noindent
Maple actually has two plotting functions for contours of $f(x,y)$.
Recall that, given a real number $c$, the contour of $f : D \to {\bf R}$ for 
the value $c$ is the set 
$$\{(x,y) \in D : f(x,y) = c\}$$
The {\tt contourplot} command produces a 2D contour plot.  The basic format
is 
\medskip
\centerline{\tt contourplot(expression,xrange,yrange,options);}
\medskip
\noindent
For example, try
\medskip
\centerline{\tt contourplot(x\^{}2 - y\^{}2,x=-3..3,y=-3..3);}
\medskip
\noindent
and see how this matches up with your density plot.  
There are a number of options available with this command, including
ways to specify the numbers of contours to be drawn, the $c$-values,
and so forth.  All this information and example
commands illustrating the various things you can do are
available from Maple's {\it on-line Help}.  Type in the 
command {\tt ?contourplot} (or use the Help pulldown menu)
to see it.
 
\bigskip
\noindent 
There is a second command called {\tt contourplot3d} that 
plots the contours ``raised to the appropriate planes $z = c$''.
In other words, the output of {\tt contourplot3d} shows a 
collection of horizontal slices of the set
$$\{(x,y,z) \in {\bf R}^3 : z = f(x,y)\}$$
The output from a {\tt contourplot3d} command is a 3D graph which
can be rotated and manipulated in the same way that the {\tt spacecurve}
plots we saw in Lab 1 can.  For example, try experimenting with:
\medskip
\centerline{\tt contourplot3d(x\^{}2-y\^{}2,x=-3..3,y=-3..3);}
\medskip
\noindent
{\it 3. Plotting of graphs: $z = f(x,y)$}
\bigskip
The  command for 
3D plotting is called {\tt plot3d} (naturally enough!)  Its format
is similar to, but not exactly the same as the format of {\tt plot}.
To draw a graph with {\tt plot3d\/}, you use a command of the format:  
\medskip
\centerline{\tt plot3d(function,xrange,yrange,options);}
\medskip\noindent
The {\tt function} is the function $f(x,y)$, entered
in the usual Maple syntax for expressions. The {\tt xrange}
and {\tt yrange} specify a rectangular box in the plane that the 
plot will be constructed over; the {\tt options} can be
used to specify how the plot is drawn.  Look at the online help
for {\tt plot3d[options]} if you want to see what things are 
possible.  Most of the options can also be invoked from the 
3D graphics output via the pop-up menu from the graphics
output, or the 
toolbar buttons.  Using the PATCHCONTOUR
style is often a very effective way to visualize the shape of a surface.
(It also shows contours, ``lifted to the appropriate plane $z = c$'', 
as curves on the surface $z = f(x,y)$.)

For example, try
\medskip
\centerline{\tt plot3d(-x\^{}4+2*x\^{}2-x/2-y\^{}2-1,x=-2..2,y=-2..2);}
\medskip
\noindent
to plot the surface
$$z = -x^4 + 2x^2 - x/2 - y^2 - 1.$$

One very nice feature of Maple 3D graphics is that you can change viewpoint,
add axes, etc. using the mouse and the 
toolbar options in the 3D graphics window.  The method is the same as
that for the {\tt spacecurve} graphs from Lab 1.
\bigskip
\noindent
{\bf Assignment}
\bigskip
Exercises 1, 2, 3 from Discussion 15 in the Damiano/Freije
Collaborative Learning  Workbook.  Due: Monday, October 4.
\bye