Math 215 – Calculus III
- Course Information
- Syllabus
- Solutions
- Maple Labs
- Maple Tutorial
- Sample Maple Session
- Lab Project 1
- Lab Project 2
- Lab Project 3
- Lab Project 4
- Lab Project 5
- triple.html
- Maple Demos
- Maple HowTo
- refcard.pdf
+ Homework
- Practice Exams
- Student's Guide
- Help!
(Off this site)
Web Homework
Math Lab
Instructor Directories
Math Careers
Student Data Sheet

Math 215 Lab Project 2

Graphs and Level Curves


  • To learn how to use Maple to visualize graphs of functions of two variables.
  • To visualize the relationship between graphs of functions of two variables and contour curves.
  • To visualize the geometry of critical points of a function of two variables.

Packages in this lab

To 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 xy-plane over which you want to plot the graph. As our main example, we consider the function f(x,y) = 2*x^3+xy^2+5*x^2+y^2 over the rectangle R=[-2,1]x[-3,3] .

First, let us define the function f in Maple .

> f:=2*x^3+x*y^2+5*x^2+y^2;

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):

[Maple Plot]

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 ( Axes button ).

> display(surface,axes=NORMAL);

[Maple Plot]

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 ( PATCHNOGRID button ),

> display(surface,axes=NORMAL,style=PATCHNOGRID);

[Maple Plot]

or by changing coordinate axes to a coordinate box ( Axes box ):

> display(surface,axes=BOXED);

[Maple Plot]

The difference in scales between the xy-plane and the z-axis is now very clear. It can be fixed by choosing scaling=CONSTRAINED option ( CONSTRAINED option ):

> display(surface,axes=BOXED,scaling=CONSTRAINED);

[Maple Plot]

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 xy-plave. You can do it by choosing a viewable range for the z-coordinate (it may take a few attempts to find a good range for z):

> display(surface,axes=BOXED,scaling=CONSTRAINED,view=-3..5);

[Maple Plot]

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]);

[Maple Plot]

Level Curves

By default, the rectangular grid visible on the plot of our surface is the image of the coordinate grid on the xy-plane. Another interesting grid is obtained by choosing style=PATCHCONTOUR option ( PATCHCONTOUR button ):

> display(surface,axes=BOXED,view=-3..5,orientation=[105,45],style=PATCHCONTOUR);

[Maple Plot]

The black lines that you see are the lines of intersection of our surface with planes parallel to the xy-plane (equations of such planes arez = const ). 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);

[Maple Plot]

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);

[Maple Plot]

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]);

[Maple Plot]

You can also plot contour lines only by either choosing style=CONTOUR option ( CONTOUR button ),

> display(surface,axes=BOXED,view=-3..5,orientation=[105,45],style=CONTOUR);

[Maple Plot]

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);

[Maple Plot]

If you look at this graph straight from the top, you will see a collection of curves on the xy-plane. These curves are called level curves and they have the equations f(x,y) = c, where z = c is the equation of the corresponding plane. Note that because of our restriction to the z-range, the value of c is taken between -3 and 5.

> display(surface,axes=BOXED,view=-3..5,orientation=[270,0],style=CONTOUR,color=red,contours=15);

[Maple Plot]

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 xy-plane, and the resulting picture is two-dimensional. Also notice that the contours fill the whole picture (in contrast with the previous plot, there is no restriction to the values of c).

> contourplot(f,x=-2..1,y=-3..3,contours=20);

[Maple Plot]

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);

[Maple Plot]

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]):

[Maple Plot]

Critical Points

There 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 f 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);

[Maple Plot]

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 ), (-5/3, 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 f(-1,2). 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);

[Maple Plot]

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 f decreases.

> contourplot(f,x=-0.5..0.5,y=-0.5..0.5,contours=51,coloring=[blue,red],numpoints=1000,scaling=CONSTRAINED);

[Maple Plot]

> contourplot(f,x=-2.0..-1.4,y=-0.3..0.3,contours=51,coloring=[blue,red],numpoints=1000,scaling=CONSTRAINED);

[Maple Plot]

So, based on the color information, we see that (0,0 ) is a local minimum, and (-5/3, 0 ) 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]):
display({plot3d(f,x=-0.5..0.5, y=-0.5..0.5,style=PATCHCONTOUR,contours=20),

[Maple Plot]

> shift:=plottools[transform]((x,y)->[x,y,3.9]):
display({plot3d(f,x=-2..-1.4, y=-0.3..0.3,style=PATCHCONTOUR,contours=20),
shift(contourplot(f,x=-2..-1.4, y=-0.3..0.3,contours=20,coloring=[blue,red]))},

[Maple Plot]

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]):
display({plot3d(f,x=-1.5..-0.5, y=-1.5..-2.5,style=PATCHCONTOUR,contours=20),
shift(contourplot(f,x=-1.5..-0.5, y=-1.5..-2.5,contours=20,coloring=[blue,red]))},

[Maple Plot]

> shift:=plottools[transform]((x,y)->[x,y,2]):
display({plot3d(f,x=-1.5..-0.5, y=1.5..2.5,style=PATCHCONTOUR,contours=20),
shift(contourplot(f,x=-1.5..-0.5, y=1.5..2.5,contours=20,coloring=[blue,red]))},

[Maple Plot]


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);

[Maple Plot]

Now rotate this graph to restore its three-dimensional character.

> display(surface,axes=BOXED,orientation=[-117,72],style=PATCHCONTOUR,contours=20);

[Maple Plot]

Additional topics

Locating Critical Points using Calculus
GIF file with formulas
Locating Critical Points using Maple

To 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 fwith respect to x 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};

{2*x*y+2*y = 0, 6*x^2+y^2+10*x = 0}

Maple's solve command does that.

> solve({diff(f,x)=0,diff(f,y)=0});

{y = 0, x = 0}, {y = 0, x = -5/3}, {x = -1, y = 2},...


Valid XHTML 1.0!
©2003 The Regents of the University of Michigan
Last Modified: Mon Sep 1 21:45:07 2003