Lab 1B - Graphing Functions of Two Variables and Quadric Surfaces
Math 2374 - University of Minnesota
http://www.math.umn.edu/math2374
Questions to: rogness@math.umn.edu
Introduction
Remember to evaluate the initialization cells in math2374.nb before continuing on with this lab.
At the end of Lab 1A you learned how to use Mathematica to plot the graph of equations such as or . As you hopefully remember, we have to use different commands to plot the graphs of these two equations. In the first case, we have explicitly solved for y as a function of x; there is a single y on the left hand side of the equation, and no occurrences of y on the right hand side. In cases like this we can use the Plot function to show a graph of y. In the second case we have an implicit function of y. We can't solve explicitly for y because we end up with ±on the right hand side. (This is not a well defined function because for a given value of x we can only have one value, not a positive and a negative value.) We learned how to use the command ImplicitPlot to handle equations like this.
In this lab we're going to work with the three-dimensional analogs of these commands and, as you might expect, we'll have to consider two different cases. The first is when we have a function of x and y which is explicitly solved for z, e.g.
We'll also consider implicit functions of z, such as
(Note that if you tried to solve this last equation for z, you'd have the same problem with a ± sign.)
The first case is considerably easier, and we'll deal with that one first. One other comment before we move on: some of the equations in this lab might look a bit small on your screen. If you're having trouble reading them, try the menu option Format : Screen Style Environment : Presentation.
Plot3D
Suppose we define a function z=f(x,y) of two variables, e.g.
In[38]:=
Out[38]=
What does a graph of this function even mean? The definition usually given is "the set of all points of the form (x, y, f(x,y)) such that (x,y) is in the domain of f," but you may not find this particularly enlightening.
Notice that the function f takes two inputs, x and y, and returns a single number, which we call z. If we draw the x-y-z coordinate axes in the standard way, the z-axis represents height, and this is the key to graphing f(x,y). If you choose a point (x,y) in the xy-plane, then z=f(x,y) represents the height of the graph at that point. For example, here's the graph of a simple function, g(x,y)=1. This means that no matter what values you choose for x and y, the function g will always return ("a height of") one.
In[39]:=
Out[39]=
Out[40]=
As you can see, we're using the command Plot3D to create this graph. The syntax of Plot3D is very similar to that of Plot; you first give it a function of x and y, and then ranges for x and y.
Here's a slightly more complicated function. Before you evaluate this cell, see if you can predict what the graph will look like.
In[41]:=
Out[41]=
Out[42]=
This graph does not have a constant height of one, but if you look at the definition of g(x,y) you should be able to make some observations:
• if , then g(x,y)=0.
• if x and y are both positive, then .
• if x and y are both negative, then .
Looking back at the picture, are these things true? One thing you have to notice is that the z-axis goes from -2 to 2, which means the "height" is zero halfway up the box, not at the bottom. Another thing worth pointing out is that the z-axis is scaled differently than the x- and y-axes. If you want to change the scaling, you can use the option BoxRatios, which you can look up in the Help Browser:
In[43]:=
Out[43]=
Let's plot the function we considered previously so that we have something slightly more interesting to work with.
In[44]:=
Out[44]=
Another useful option is ViewPoint. The effect of this option is to pretend you're floating in space at some point (x,y,z) -- which you specify -- looking back at the origin. For instance, if we want to look at the previous graph from straight above, we can set the viewpoint to be (0,0,10):
In[45]:=
Out[45]=
The output isn't terribly interesting. (Why?) You should try graphing f(x,y) on your own a few times, choosing different viewpoints each time. You should also try using the BoxRatios option and see if it makes a difference.
We could spend an entire lab having you plot the graphs of all sorts of functions. Some of the most interesting involve trigonometric functions like Sin:
In[46]:=
Out[46]=
This graph moves up and down so much that Mathematica's picture is kind of choppy. We can fix this by forcing Mathematica to compute the height of the graph (i..e. the z-value) at more points before it starts to fill in the gridlines. This is done with the PlotPoints option:
In[47]:=
Out[47]=
If you don't like the gridlines, you can turn them off with the Mesh option:
In[48]:=
Out[48]=
Sometimes when you're changing viewpoints it's easy to lose track of which axis is the x-axis, and which is the y-axis. You can label them with the AxesLabel option:
In[49]:=
Out[49]=
Or, if you don't want to have the axes numbered, you can use the Axes option. (If you want the box to disappear entirely, try adding Boxed→False to this command.)
In[50]:=
Out[50]=
Exercise 1
Do problem 1.2.13 on page 16 of your textbook. Use Mathematica to graph the functions and then match them with the pictures on the right. You will make your life easier if you match the x- and y- ranges in the Plot3D commands to the ranges in the figures. The PlotPoints and BoxRatios options might also be useful. Note that the viewpoints in the figures might be different than the default viewpoint in Mathematica.
If you name the functions before plotting them, remember to use lower-case names as discussed last week or you will run into problems.
While we'd like to you to put some effort into identifying each graph, you will only hand in a careful write up one particular match. For example, if you're told to write about B(x,y), you should carefully explain why B(x,y) produces the graph that it does. Use the definition of the function to explain the shape -- why is it high in some areas, low in others? Is it ever equal to zero? Is it ever negative, or is it always positive? etc.
Your TA will tell you which function has been chosen for you to describe.
ContourPlot
Before we work with implicit functions, we're going to introduce one more way to examine the height of a surface. If you've ever done any kind of hiking outdoors or fishing on a big lake you're probably familiar with topographic maps. These maps use so-called "contour lines" to represent elevation. For instance, on standard United States Geological Survey maps, each contour line represents 10 feet of elevation. If you'd like to see an example of a topographic map, copy the following link and paste it into a web browser to see to a topographic map of Eagle Mountain, the highest mountain (well... hill) in Minnesota.
http://maps.dnr.state.mn.us/cgi-bin/drgs.pl?x=672154.0000&y=5281552.0000&size=3&layer=100k
The contour lines on this map represent elevation above sea level. Notice how in some places the lines are very close together, which represents a steep slope. In other places the lines are further apart, which represents a more gradual slope. Not surprisingly, the steepest slopes seem to be very near the summits of Eagle Mountain and Moose Mountain.
Mathematica can draw a topographic map of a surface for us. For example, let's look at a map of this function:
In[51]:=
To draw the topographic map, or "contour diagram," of the function, we use the command ContourPlot. We have to give the command the function we want to plot, and ranges for x and y:
In[52]:=
Out[52]=
Notice that Mathematica shades the picture according to elevation. The darker regions represent the lower points; the lighter shades represent higher points. Scroll back and look at the graph of f(x,y) generated by Plot3D and see if this contour diagram makes sense to you. Notice in particular that the contour lines get closer to each other near the edges of the diagram. Why is this and what does this mean? (If you're not sure, talk to the students next to you and/or your TA before you go on.)
ContourPlot3D
The three-dimensional equivalent of ImplicitPlot, which we used to graph equations such as , is not called ImplicitPlot3D as you might expect. It's actually called ContourPlot3D, and it's technically the three-dimensional analog of ContourPlot. (As it turns out, ImplicitPlot is really a special case of ContourPlot, but you don't need to understand why. The reason has something to do with level curves, which are defined in chapter 3. The reason ContourPlot3D is the generalization of ImplicitPlot has something to do with level surfaces, which are also defined in chapter 3.)
Suppose we want to graph an implicit function of z like this:
(Hopefully you recognize that this is the equation for the unit sphere.) To graph this function using ContourPlot3D, you'll have to accept on faith alone that you should move everything to the left hand side of the equation, so you have a zero on the right hand side:
The reasons for doing this aren't really important now, and we can't really explain it until we've covered level surfaces in chapter 3, so you'll just have to trust us for now.
Next we pass the expression on the left hand side of this equation to ContourPlot3D, along with ranges for x, y, and z!
In[53]:=
Out[53]=
Notice that we chose the ranges for x, y, and z to go from -1 to 1. These ranges have a great influence over the resulting picture. If you make them too large, the command will run much faster but the picture will look awful. If you make them too small, you won't see your sphere (because you'll actually be inside it). Try changing all of the ranges above to {_,-3,3} and {_,-1/2,1/2} to see examples of this.
The point is this: when you use ContourPlot3D you should put careful thought into your ranges.
One other note: you can plot any kind of equation with x, y, and z using ContourPlot3D. It doesn't have to be an implicit function of z like the equation of the sphere. For example, to graph this equation from above,
z = ,
we first move everything to the left hand side:
z - = 0.
Then we use the command:
In[54]:=
Out[54]=
However, if you can use Plot3D, it generally makes better pictures. Compare the picture from the previous command to this one:
In[55]:=
Out[55]=
Interactive 3D Graphics
The command in this section is defined in math2374.nb, and it depends on a certain Java program being located in the correct place. If you're trying to use Mathematica at home or in an IT Lab, this command may not work. You can look at the course web page to find tips about how to make it function correctly.
The three-dimensional graphs that Mathematica can produce are great, but it can be very tedious to adjust the ViewPoints if you want to get a different look at your function. In today's interactive world, we could argue, we ought to be able to rotate the pictures, zoom in and out, and so on. While Mathematica has never put much effort into these capabilities, we've incorporated a Mathematica add-on called "LiveGraphics3D" which will let you rotate things to your hearts content.
It works like this. Suppose you want to look at a certain picture, like this one from earlier:
In[56]:=
Out[56]=
Notice that we used a name -- "graph" -- for the picture. Now, instead of using the Show command, we'll use a new command called ShowLive:
In[57]:=
Out[57]=
If all goes well, evaluating the previous cell will make an extra window pop up on your monitor. [Note: in this web version, the picture has been embedded above in the notebook; you can click on it and rotate it within the web page.]. Now you can interact with the picture in this new window. Click on it and move your mouse to rotate it. If you hold the shift key down, you can click on it and move your mouse up and down to zoom in and out. To reset the image, press the "Home" key.
You can basically use the ShowLive command anytime that you would use the Show command with a 3D picture, although it doesn't always work with the same options. If something goes wrong you'll get a small windows with a (possibly incomprehensible) error message. Just close the window and try something different.
Note that every time you use the ShowLive command, you'll create a new little window. Make sure you close them when you're done, or you'll end up with a lot of clutter on your virtual desktop.
There's also an interactive version of Plot3D you can use, called Plot3DLive, which means you can use LiveGraphics3D to look at a graph without having to plot it separately before using ShowLive:
In[58]:=
Out[58]=
Note that using the Live commands can really slow down some computers, especially if you use a high PlotPoints setting.
The downside to using Plot3DLive is that the input and output is not sorted next to each other, so you can lose track of what command created what picture. Also, if you'd like to print out a picture, you'll have to use the regular old Plot3D command.
LiveGraphics3D can do some other really cool things. For example, instead of just adjusting your viewpoint and magnification of a surface, we've set up some examples where you can interactively change the picture! You may have already used some of the interactive demos posted online. Although it's possible to run these from within Mathematica, we'll usually ask you to go to a web page instead.
Quadric Surfaces
The graphs of functions of two variables are examples of what we call surfaces. More generally, a set of points (x,y,z) that satisfy an equation relating all three variables is often a surface. A simple example is the unit sphere, which you graphed above with ContourPlot3D. (The sphere is the set of points which satisfy the equation )
In this section we're going to analyze some equations which involve and we'll look at their graphs. The surfaces in question are known as quadric surfaces, and will provide important examples for the rest of the course. There are six different quadric surfaces: the ellipsoid, the elliptic paraboloid, the hyperbolic paraboloid, the elliptic cone, and hyperboloids of one and two sheets.
In the first lecture of the semester, you talked about 3D graphs and how to analyze cross-sections of quadric surfaces. This is where you choose a specific value for or . For example, consider the quadric surface given by the equation
To check the horizontal cross-sections, we'd choose values for , such as . In this case,
or
So we see that the cross section in the plane z=36 is an ellipse which stretches 3 units in the positive and negative x-direction, and 2 units in the positive and negative y-direction.
If you don't remember how to graph ellipses and hyperbolas, this might be a good time to ask your TA to review those things.
Rather than have you read through a long section where we work out the
cross sections of all the quadric surfaces, we're going to send you to an
interactive gallery instead. Go to the following page in your
web browser.
http://www.math.umn.edu/~rogness/quadrics/
The gallery also includes another short review about cross
sections, along with a picture. Once you've spent some time
browsing through the gallery, you're ready to continue on with this
lab. You can use the gallery as a reference throughout the
semester.
Graphing Quadric Surfaces in Mathematica
You can use the commands you learned earlier in this lab to graph any of the quadric surfaces. Some of the equations, such as , are explicitly solved for z, so you can graph using Plot3D. Others, like or , are implicit functions, so you have to use ContourPlot3D. Below you can see an example of graphing each kind of surface.
Elliptic Paraboloid
This shows the graph of .
In[59]:=
Out[59]=
Hyperbolic Paraboloid (Saddle)
This shows the graph of .
In[60]:=
Out[60]=
Ellipsoid
This displays the graph of .
In[61]:=
Out[61]=
Double Cone
This shows the graph of .
In[62]:=
Out[62]=
Alternatively, you can solve for z and graph the upper and lower parts separately before putting them together.
In[63]:=
Out[63]=
Out[64]=
Out[65]=
Hyperboloid of One Sheet
This shows the graph of .
In[66]:=
Out[66]=
Hyperboloid of Two Sheets
This shows the graph of .
In[67]:=
Out[67]=
A preview of what's to come...
Some people feel that using Plot3D to graph a paraboloid or cone results in an ugly picture, because the surfaces are plotted over a square in the xy-plane. (For example, the square where -1≤x≤1 and -1≤y≤1.) To get nicer pictures, like those in the book, we'd like plot these surfaces over a circular domain in the xy-plane. We don't have the resources to do that yet, but you'll learn how in Lab 2B. If you want a little preview, you can evaluate the followingcells. Don't bother trying to understand the commands yet!
In[68]:=
Out[68]=
In[69]:=
Out[69]=
In[70]:=
Out[72]=
Exercise 2
Find a function whose contour diagram is as similar as possible to the following picture. You don't need to completely match every detail, but your answer should have contour lines which are not evenly spaced, and they should be ellipses, not circles or squares. Pay careful attention to the colors; recall that the shades from ContourPlot correspond to the height of the function, and lighter shades are higher. If your contour lines are correct, but the shading scheme is reversed, then you haven't finished the problem.
Hint: Use the "Student Axiom," i.e. if this exercise is part of the section on quadric surfaces, then the required functions are probably quadric surfaces.
Exercise 3
Do Exercise 2 for the following new graph. Again, be careful about the colors, and notice that the contour lines are evenly spaced in this picture.
Exercise 4
Consider the surface given by . Make an accurate picture of this quadric surface by drawing the cross sections given by z=0, z=±2, x=0, x=±2, y=0, y=±2, and any others which might be helpful. Note that this exercise is easier to do by hand than with Mathematica, although the online gallery of quadric surfaces could be useful.
Exercise 5
Consider the surface given by . Make an accurate picture of this surface by drawing the cross sections given by x=0, x=±1, y=0, y=±1, z=0, z=±1, and any others which might be helpful. As with Exercise 4, this is probably easier to do by hand, but the online gallery could help.
Exercise 6
So far all of our quadric surfaces have been centered at the origin, but that's not always the case. You can move them around using the same methods you've used in Calculus and PreCalculus -- replacing "x" with "(x-h)" and so on. Find the equation for a double cone which:
(1) has a vertex at (1,1,2),
(2) and intersects the xy-plane (i.e. the plane z=0) in a circle of radius 4.
Credits
Created by Mathematica (January 28, 2004)