An introduction to plotting with Maple
Worksheet by Mike May, S.J.- maymk@slu.edu
Introduction
In previous courses you have been using a graphing calculator to graph functions of one variable. Having a convenient grapher makes the concepts of calculus easier to understand.
However, most of Calculus III deals with functions of several variables and our calculators are not very good at graphing surfaces. The point of this worksheet is to give an introduction to graphing with Maple. This should make it easy for you to produce the relevant pictures for this course.
An introduction with functions of one variable:
A Simple Plot
Since functions of one variable are more familiar, we start with them.
The syntax for plotting a function of one variable is
plot("function of x", x="low value of x".."high value of x");
where the expressions in quotation marks are to be replaced by appropriate values.
Hit enter to execute the command below.
Things to notice:
Exercises
1) Plot the graph of y = cos(2*x) with .
Stretch the graph to cover the screen.
2) Replot the graph above, but modify the style so that it is done with dots rather than with connected lines, and so the axes are on the sides of the graph rather than in the middle of them.
3) Replot the graph above, but modify the style so that it is a connected curve, with no axes, and the same scale for the x and y axes.
Specifying the y-range
We would like to be able to specify the y-range of a plot.
If a plot has a vertical asymptote, Maple will give such a large y-range that we miss details we are interested in. The solution is to specify the y-range. Specifying the y-range is done using the same conventions used to specify the x-range. The command
becomes
plot("function of x", x="low value of x".."high value of x", y="low value of y".."high value of y");
For an example, execute the plotting commands given below.
The second graph is much more informative than the first about the behavior of this function.
It is worthwhile at this point to note where we have been using imprecise language. By "x-range" we mean "the range of the independent variable", while "y-range" is "the range of the dependent variable". Equivalently, x-range and y-range respectively stand for the ranges of the input and output variables. The examples below show what happens when we change the names of the variables.
Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct
Notice that we can use any letter for input and output, but the input range is specified before the output range or we get an error. With the error it is worth pointing out where maple hides some stuff. Put the cursor in the line containing the last plot command and select "Expand Document Block" from the View menu.
Plotting several functions on the same graph
It is also useful to be able to see the graphs of several functions on the same graph. In Calculus I and II we were interested in seeing the graph of a function and its derivative at the same time. We also wanted to compare a function with the polynomial approximations we obtained for it.
To plot several functions at the same time, the command
plot({"function1 of x", "function2 of x", "etc."}, x="low value of x".."high value of x");
Note that the set of functions is enclosed in braces.
For an example, consider the following commands which plot cos(x) along with some of the Taylor polynomial approximations of cos(x).
More Exercises
4) Produce a nice plot of the graph of y = tan(x) with x between 0 and 10. You will need to specify the y-range.
5) Plot with , along with the lines tangent to that graph when x = -1.5, -.5, .5, and 1.5. Crop the graph to show the region where y is between -2 and 4.
As was noted earlier, you can graph a function of one variable on a graphing calculator. Often, a calculator will be the easier way to deal with such graphs. There are two reasons to look at them with Maple when your calculator is already at hand:
Plotting with functions of two variables:
Basic Plotting
The syntax for plotting the graph of a function in 2 variables is similar to the one variable case. We use the command:
plot3d("function of x and y", x="low x".."high x", y="lowy".."high y");
as we see with the following command.
Once again, if you click once on the graph, it will be enclosed in a box, and a set of buttons will appear up on the menu bar. There are 2 boxes labeled and with scroll arrows for specifying the viewing angle, a drop down list of 7 buttons for style used on the graph itself, a drop down list of 4 buttons for style used on the axes, a "1:1" button to use the same scale on all 3 axes, and a drop down list of 3 possible actions of dragging on the graph.
The default has a wire frame model, that is opaque (the front bump hides the back bump), the axes are not printed, from a viewing angle of 45 degrees on both angles.
Exercise
6) Redraw the graph given above. Then use the buttons to produce an image that:
A) Shades the image, draws a grid of lines on the image, and boxes the axes around the image;
B) Shades the image and draws contour lines on it, while putting the axes in standard position through the origin;
C) Uses a wire frame model with contour lines, and suppresses the axes.
Viewing angles and contour plots
The list of controls for changing the appearance of a graph includes controls for theta and phi, the coordinates of the position in spherical coordinates that the graph is viewed from. The angle phi is the angle to the positive z-axes. Thus an angle of
looks down on the x-y plane from above,
gives a viewpoint looking down the x-y plane, while looks up from below. The angle theta measures the rotation of the x-y plane. If so we are looking down the z-axis, then θ=0 has the y- axis horizontal increasing from left to right and the x-axis vertical decreasing as you go up. The default setting has and both set to 45.
Exercises:
7) Redraw the graph above. Adjust the viewing angle so that theta = 60 and phi = 30. Use a wireframe model that is opaque, and have the axes on the outside of the graph.
8) Find the angle settings that look down the z axis and put the x-y plane in standard position for the plane. (Standard position has the x-axis horizontal and increasing to the right. The y- axis is vertical and increasing as you rise.)
The correct settings are.....
9) View the graph above as a contour map with the x-y plane in standard position.
This contour map view can be obtained more directly with the plots[contourmap] command, using
plots[contourplot]("func(x,y)", x="low x".."hi x", y="low y".."hi y"); The plots[contourplot] command has the option of letting you specify which contours will be drawn with a
contours=["list of values" option. Thus to get the map above with contours corresponding to the values of -2/3, 0, 1/4, and 5/4 we use the command:
plots[contourplot](sin(x) + sin(y), x=-3..5, y= -Pi..2*Pi, contours= [-2/3, 0, 1/4, 5/4]);
10) Redraw the contour plot you found in the last exercise, using the plot options rather than adjusting the controls and redrawing.
Multiple graphs and controlling the z-range
The syntax for doing more than one graph on the same plot is similar to the one variable case. We simply replace the function with a set of functions.
The control of the z-range is done with a
view = "low value of z".."high value of z"
clause inserted into the plot3d command.
11) Plot the functions
and on the same axes. Plot over the rectangle with x and y between -1 and 3.
12) Regraph the same pair of functions, this time constraining the z-range between -1 and 7.
These 2 surfaces have a simple relationship. Describe the relationship and replot the graph viewed at an angle to make the relationship clear visually.
The relationship is.......
The viewing angle that makes this obvious is ......
Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.