This tutorial will guide you through the basic operations necessary to use Sage to handle basic surface graphing in 3D. Sage is a powerful tool; we'll only just begin to see its capabilities here. If you are interested you can learn much more about its capabilities at http://www.sagemath.org.
If you are reading this as a "published worksheet" and have not yet done so, look for the "Edit a copy" text in the upperleft corner of the page and click on it. That will make this worksheet available for you to use and change. For the instructions below to make sense, after you've made your own copy of the worksheet, use the "Action" pulldown menu to select "Delete All Output". This will create the graphs one at a time as you work through them.
We'll begin by learning how to interact with the worksheet interface. It's quite straightforward with the exception that to evaluate a command you must either press "shiftenter" or click the "evaluate" link below the command entry cell. Pressing "enter" alone will merely create a new line in the command entry cell.
Click on the cell below to select it. Hold the shift key down and press the enter key or click the "evaluate" button to evaluate the cell's contents.


If you want, you can change the function in the above command to plot different functions. Remember that we've defined the variables x, y, and z so those are the only ones you can use (unless you define others). Just retype the function, change the range for the independent variable (if necessary) and press shiftenter. This can be repeated as many times as you like.
Alright, let's start some 3D graphing.
Example 1: Plot the right circular cylinder given by x^{2} + y^{2} = 1.
First we begin by declaring the variables we will use. This only needs to be done once, but if you reload this worksheet you'll need to evaluate this cell again (or use the "Action" pulldown menu and select "Evaluate All").
Next we plot the surface. If the function we want to plot can be written as z=f(x,y) then we can use the plot3d() function. If, however, z is implicit (or missing, meaning the expression should be true for all z), we need to use implicit_plot3d(). The first argument is the equation we want to plot (be sure and use == for equality) and the next three arguments specify the range for each axis)

If your browser supports Java applets you can rotate and scale the graph. Click on the "Make Interactive" button. If requested, allow the JmolApplet to run. Now press and hold the left mouse button while the pointer is on the figure to change its orientation. Doing the same with the middle mouse button allows you to zoom in or out. It takes some practice to figure out how to move it the way you want. If you want to "start over," merely reevaluate the cell that draws the figure.
Example 2: Next we want to plot the elliptic paraboloid given by z = x^{2}/2 + y^{2}. Since this is written in the form z = f(x,y) we can use the regular plot3d() function. The first argument is the function, the next two specify the range for the axes, and the last argument (called a named argument) causes the color to vary with z value.

We could, of course, plot the same function using the implicit_plot3d() function...

We can place restrictions on one or more variables to help us see the plot. For example, often we draw paraboloids with the opening bounded by an ellipse. To do this for this example we want 0 <= z <= 4. The "region" parameter takes a Python "lambda" function with three variables and specifies the portion of the range we want to see.

Example 3: We can also plot planes. The plane 3y − z = 2 is plotted using the color blue:

Example 4: The surface given by z = y^{2} − x^{2} is a hyperbolic paraboloid.

Example 5: Sometimes we want to see two surfaces at once, perhaps to study the curve formed by their intersection. This can be done with two plot3d() commands displayed together. Here we show the plane and hyperbolic paraboloid we've just examined together on one plot Notice how the opacity named parameter can be used for a translucent effect. An opacity of 0.0 means completely transparent whlie an opacity of 1.0 means completely opaque.

Example 6: Finally, we draw the ellipsoid x^{2} + y^{2}/9 + z^{2}/4 = 1. This function is implicit for z so we use implicit_plot3d() as in the first example.

You can find out all about the functions we've used here, including different options that can be used to control how they work, by reading the help information about them. To read help about a command in Sage you only need to type the command name followed immediately by a question mark and then press shift enter (or click on "evaluate").
That wraps up this tutorial. Below are some additional examples. Sage does many other things that you might find helpful in this class and other math classes. We may use it again during the quad, but if your interested in finding out more you should feel free to talk with the professor.






