![]() |
Math 215 Lab Project 2Graphs and Level Curves
Objectives
Packages in this labTo be able to use the Maple commands described in this section, you need to load the plots package. > with(plots): Warning, the name changecoords has been redefined Graphs of two-variable functions (surfaces)Plotting a graph of a function of two variables in Maple is done by
the plot3d
command. You need to specify the function you are plotting and the rectangle
in the First, let us define the function > f:=2*x^3+x*y^2+5*x^2+y^2;
We are going to choose different options for displaying the resulting surface. For this, it is convenient to create first a basic plot of our function using plot3d command, give it a name (say, surface ), and then use it in the display command. Reminder: When a plot is assigned to an expression, you need to suppress the output and terminate the command with : , and not ; , surface:=plot3d( ... ): . Note that many options can be changed both in the display command and interactively, by either using a 3-D Plot Menu Bar ( left-click on the graph to select it and this menu will appear in the Worksheet Toolbar ), or by using a context-sensitive menu ( right-click on the graph to call it up). > surface:=plot3d(f,x=-2..1,y=-3..3):
First thing to remember is that Maple rescales the graph to fit it all
in the window, so many interesting features of the graph will not be visible.
To see the rescaling, add the coordinate axes ( > display(surface,axes=NORMAL);
Unfortunately, our surface overlaps with the coordinate cross and the resulting
plot is a bit overcrowded. You can improve it by either turning off the coordinate
grid on the surface ( > display(surface,axes=NORMAL,style=PATCHNOGRID);
or by changing coordinate axes to a coordinate box ( > display(surface,axes=BOXED);
The difference in scales between the > display(surface,axes=BOXED,scaling=CONSTRAINED);
Now the scale is right, but the interesting part of the picture is too small.
Let us cut off the peaks and look for the part of the surface near the > display(surface,axes=BOXED,scaling=CONSTRAINED,view=-3..5);
By left-clicking on the graph and then dragging the mouse, you can rotate your picture. Once you are satisfied with the result, you can add the rotation angles to the display command. Also, at this point we know exactly how our surface looks like, so we can drop the scaling=CONSTRAINED option. This improves the graph and we know that we are not missing any of its the important features. > display(surface,axes=BOXED,view=-3..5,orientation=[105,45]);
Level CurvesBy default, the rectangular grid visible
on the plot of our surface is the image of the coordinate grid on the > display(surface,axes=BOXED,view=-3..5,orientation=[105,45],style=PATCHCONTOUR);
The black lines that you see are the lines of intersection of our surface with
planes parallel to the > display({surface,plot3d(2,x=-2..1,y=-3..3,color=yellow,style=PATCHNOGRID)},axes=BOXED,view=-3..5,orientation=[105,45],style=PATCHCONTOUR);
You can increase the number of contours (default number is 15), > display(surface,axes=BOXED,view=-3..5,orientation=[105,45],style=PATCHCONTOUR,contours=30);
or plot contour lines corresponding to specific heights: > display(surface,axes=BOXED,view=-3..5,orientation=[105,45],style=PATCHCONTOUR,contours=[-1,0,1,3,3.5]);
You can also plot contour lines only by either choosing style=CONTOUR
option ( > display(surface,axes=BOXED,view=-3..5,orientation=[105,45],style=CONTOUR);
or by using a special Maple command contourplot3d . You might want to make the contour lines uniformly colored to improve visibility. > contourplot3d(f,x=-2..1,y=-3..3,axes=BOXED,view=-3..5,orientation=[105,45],color=red);
If you look at this graph straight from the top, you will see a collection
of curves on the > display(surface,axes=BOXED,view=-3..5,orientation=[270,0],style=CONTOUR,color=red,contours=15);
Now try to rotate this picture to restore its three-dimensional character. Level curves can be graphed directly with the help of the contourplot
command. Note that level curves live on the > contourplot(f,x=-2..1,y=-3..3,contours=20);
The color of the contours change from yellow to red as the height decreases. This can be changed by the coloring option. You can also color the whole graph by adding filled=true option. > contourplot(f,x=-2..1,y=-3..3,contours=20,coloring=[blue,green],filled=true);
The following plot (that uses Maple command transform from a package plottools to make two-dimensional plot three-dimensional) helps to visualize the relationship between the surface and its level curves. The Maple code in this example is a bit complicated, but you do not need to use it in your lab project. > shift:=plottools[transform]((x,y)->[x,y,-3]):
Critical PointsThere are two main types of critical points for a function of
two variables: local minima/maxima and saddle points . You can
recognize the critical points of > contourplot(f,x=-2..1,y=-3..3,contours=51,numpoints=1000);
On our graph, we can see that there are local minima/maxima at
the origin (or near it) and somewhere near (-1.7,0
), and saddle points somewhere near (-1,-2 ) and (-1,2
). Note that we can not find the exact coordinates of the critical points from
the graph, we have to use Calculus. Since at the critical
points the partial derivatives of our function vanish, we find that the exact
coordinates of the critical points are (0,0 ), ( > contourplot(f,x=-2..1,y=-3..3,contours=[eval(f,{x=-1,y=2})],numpoints=1000);
Another problem with the contour plot is that we can not distinguish
between local minima and local maxima. To get around it, let's "zoom in"
and look at the contour map near the critical point. Let us also use the coloring
option. On the plot below, color of the level curves changes from red
to blue as the value of the function > contourplot(f,x=-0.5..0.5,y=-0.5..0.5,contours=51,coloring=[blue,red],numpoints=1000,scaling=CONSTRAINED);
> contourplot(f,x=-2.0..-1.4,y=-0.3..0.3,contours=51,coloring=[blue,red],numpoints=1000,scaling=CONSTRAINED);
So, based on the color information, we see that (0,0
) is a local minimum, and ( > shift:=plottools[transform]((x,y)->[x,y,0]):
> shift:=plottools[transform]((x,y)->[x,y,3.9]):
And this is how the surface and its level curves look line near the saddle points. Note the intersecting contour curves. > shift:=plottools[transform]((x,y)->[x,y,2]):
> shift:=plottools[transform]((x,y)->[x,y,2]):
We conclude our study of this surface by taking another look at its three-dimensional plot from the top. You can see the contour lines (these are not level curves) intersecting at the saddle points. > display(surface,axes=BOXED,orientation=[270,0],style=PATCHCONTOUR,contours=20);
Now rotate this graph to restore its three-dimensional character. > display(surface,axes=BOXED,orientation=[-117,72],style=PATCHCONTOUR,contours=20);
Additional topicsLocating Critical Points using Calculus |