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 twovariable 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 plane over which you want to plot the graph. As our main example, we consider the function over the rectangle R=[2,1]x[3,3] . First, let us define the function in Maple . > 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 3D Plot Menu Bar ( leftclick on the graph to select it and this menu will appear in the Worksheet Toolbar ), or by using a contextsensitive menu ( rightclick 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 plane and the axis is now very clear. It can be fixed by choosing scaling=CONSTRAINED option ( ): > 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 plave. You can do it by choosing a viewable range for the coordinate (it may take a few attempts to find a good range for ): > display(surface,axes=BOXED,scaling=CONSTRAINED,view=3..5);
By leftclicking 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 plane. Another interesting grid is obtained by choosing style=PATCHCONTOUR option ( ): > 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 plane (equations of such planes are ). These lines are called contour lines . > 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 plane. These curves are called level curves and they have the equations , where is the equation of the corresponding plane. Note that because of our restriction to the range, the value of is taken between 3 and 5. > 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 threedimensional character. Level curves can be graphed directly with the help of the contourplot command. Note that level curves live on the plane, and the resulting picture is twodimensional. Also notice that the contours fill the whole picture (in contrast with the previous plot, there is no restriction to the values of ). > 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 twodimensional plot threedimensional) 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 by looking at its contour map. Near local minima/maxima the level curves of the function look like circles or ellipses, and near saddle points they look like a collection of hyperbolas. In the next plot, we increase the number of contours to get a better picture. We also increase the number of points Maple uses to generate the plot, this makes the level curves smoother and more accurate. > 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 ), ( ), (1,2 ), and (1,2 ) (see the optional section below on how to do it using Maple ). Another important characteristic of a saddle point is that level curves of the function intersect at it. You can see it by plotting a single contour corresponding to . Note that there is no actual intersection on the graph, and the curves are not smooth near the saddle points. This illustartes that Maple plots are only approximations (although quite a good ones) of the actual situation. > 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 decreases. > 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 ( ) is a local maximum. Of course, this can be also seen by plotting our surface near these points. > 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 threedimensional 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 threedimensional character. > display(surface,axes=BOXED,orientation=[117,72],style=PATCHCONTOUR,contours=20);
Additional topicsLocating Critical Points using CalculusLocating Critical Points using MapleTo find the coordinates of the critical points of our function. we use the fact that both partial derivatives vanish at these points. Partial derivative of with respect to can be computed as follows > diff(f,x); So we need to solve the system of equations > {diff(f,x)=0,diff(f,y)=0};
Maple's solve command does that. > solve({diff(f,x)=0,diff(f,y)=0});
