Graphics in (wx)Maxima for Math 215 Bro. David E. Brown, BYU–Idaho Dept. of Mathematics. All rights reserved. Version 0.12b, of September 12, 2014 Contents 1 Introduction (Please start 1.1 About this document . . 1.2 About Maxima . . . . . . 1.3 The draw commands . . here) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 2 2 2 Calc I graphs: y = f (x) 3 3 Conic sections and other implicitly defined curves 6 4 Graphing parametric curves 9 5 Polar coördinates 10 6 Cylinders 11 6.1 Cylinders and explicit objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 6.2 Cylinders and implicit objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 7 Quadric surfaces 16 7.1 Quadric surfaces and explicit objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 7.2 Quadric surfaces and implicit objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 8 Vectors in 2 and 3 dimensions 19 8.1 Vectors in 2 dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 8.2 Vectors in 3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 9 Lines and curves in space 22 9.1 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 9.2 Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 10 More about surfaces 24 11 Cylindrical coördinates 24 12 Spherical coördinates 24 13 Parametric surfaces 24 14 Vector fields 24 1 15 More about options 24 15.1 color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 15.2 Repeated use of the same options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 16 Saving your graphs 1 27 Introduction (Please start here) 1.1 About this document This document is a sort of “how-to” or tutorial for basic graphing in Maxima, for students of Math 215 at BYU–Idaho. At the moment, it’s still in the early stages, but my students need a reference: Here it is, such as it is. wxMaxima was used to create the graphics for this document, but the instructions given here should also work in any typical implementation of Maxima (except as noted). This is a how-to, not a reference manual. You need to try the examples yourself. Later parts of the document build on earlier parts. To derive the best benefit from this document, please begin at the beginning and work your way through it. In Math 215, there are many different kinds of objects to graph, and you will create graphs in 2 dimensions and in 3 dimensions. There will be four or five different coördinate systems in which to graph, as well. Maxima and its companion graphing software can handle all of these, with alacrity. This document will start with graphs like those you needed in Calc I. Then it will progress through the different kinds of graphs in the order in which my Math 215 students meet them. 1.2 About Maxima Maxima is a very powerful computer algebra system and has many, many options for graphing. A mostly comprehensive encyclopedia of these options can be found in the “Computer Algebra Systems” section of my faculty website. wxMaxima is a graphical user interface for Maxima. In this document, I refer to Maxima, but I assume you’re using wxMaxima. Maxima doesn’t actually graph anything. It has many different commands for plotting. It uses these commands to collect information about the plot you want. The various plotting commands pass this information on to some other program to do the actual plotting.1 If you get different results than I do when using exactly the code given in the examples, it may be due to differences in the programs that do the plotting. 1.3 The draw commands This document focuses on the flexible and very powerful draw family of commands. Because plotting is not native to Maxima, you have to load the draw package before you make any plots. You only need to do this once per session. To load the draw package, execute load(draw)$. The various draw commands construct scenes out of graphics objects and display the scenes in a plot. You use different graphics objects for graphing different kinds of curves, surfaces, and other things. Table 1 gives a partial list of graphics objects available as of 2013-09-20. The list includes all the graphics objects I ever want to use in a typical multivariable calculus course. Eventually, each of these objects will be discussed in this document. There are four draw commands: • wxdraw2d, which creates plots of 2-dimensional objects in the wxMaxima window • draw2d, which creates plots of 2-dimensional objects in a separate window 1 For details, see the document Graphics in the wxMaxima GUI, on my faculty website. You must execute load(draw)$ before using any draw command. Pg. 2 of 27 Table 1: Graphics objects in Maxima 2-dimensional plots Graphics object Purpose cylindrical explicit implicit label parametric parametric surface points polar spherical vector Graphing in cylindrical coördinates Graphing y = f (x) Graphing equations Labeling things in plots Plotting parametric curves Plotting parametric surfaces in 3D Plotting points or lists of points Plotting r = f (θ) Plotting in spherical coördinates Plotting vectors 3-dimensional plots X X X X X X X X X X X X X X X X • wxdraw3d and wxdraw3d, the 3-dimensional counterparts of wxdraw2d and draw2d. Note to users of WindowsTM operating systems: When you use draw2d or draw3d to make a plot, you have to close the plot window before using either of these commands again. This is not the fault of Maxima; it’s inherent to WindowsTM . 2 Calc I graphs: y = f (x) Suppose you need to graph the function y = 4 + ln x. Note that y is all by itself, on one side of the equation. We say that the equation has been solved explicitly for y, or that y is an explicit function of x. If a function is defined by an equation but is not explicit, it’s called implicit. Examples: Some explicitly defined funcitons: Some implicitly defined functions: y = 1/x xy = 1 y = x2 2 2 x −y =1 y = −2x + 3 2x + y = 3 explicit graphics objects are for plotting explicitly defined functions. Load draw, if you haven’t already, and try the following examples. Example 2.1. Graphing y = 4 + ln x. (Note: In wxMaxima, the name of the natural logarithm function is log, not “ln”.) Enter the following Maxima code in your Maxima (or wxMaxima) notebook. Remember that to execute the code, you must press the Enter key while holding down the Shift key. draw2d(explicit(4 + log(x), x,0,25))$ The draw2d command plots things in two dimensions. The “x,0,25” part is called the horizontal plotting range. It tells Maxima which range of x-values to use for the graph. By default, Maxima decides which range of y-values to use. To change the range of y-values, see the next example. You must execute load(draw)$ before using any draw command. Pg. 3 of 27 Example 2.2. Graphing y = 4 + ln x in a slightly larger plotting window. draw2d(yrange = [2,8], explicit(4 + log(x), x,0,25))$ Example 2.3. Graphing y = ex sin x: draw2d(explicit(%e^x*sin(x), x,-3,3))$ Let’s open up the vertical range a bit. Now that we’ve graphed y = ex sin x, we have an idea of what vertical range to use. Example 2.4. Graphing y = ex sin x in a slightly larger plotting window. draw2d(yrange = [-1,8], explicit(%e^x*sin(x), x,-3,3))$ You can easily put more than object in your plot, by using additional explicit objects. Example 2.5. Graphing y = 4 + ln x and its local linear approximation at (1, 4). The local linear approximation in this case is f (x) ≈ x + 3. (Exercise: Verify this!) You must execute load(draw)$ before using any draw command. Pg. 4 of 27 draw2d(yrange = [2,8], explicit(4 + log(x), x,0,25), explicit(x + 3, x,0,25))$ If we had not restricted the vertical range with the yrange option, the plot would have gone up to y = 28. Maxima would accommodate the extra height in the graph by squashing the vertical scale, making the plot harder to read. Sometimes, using different colors for different curves makes the plot easier to read. Example 2.6. Graphing y = 4 + ln x and its local linear approximation f (x) ≈ x + 3 at (1, 4), in different colors. The horizontal plotting range has been reduced, to focus on the point where the local linear approximation meets the curve. draw2d(yrange = [2,8], explicit(4 + log(x), x,0,5), color = red, explicit(x + 3, x,0,5))$ See the subsection on the color option for a list of predefined colors. Adding a legend or key can also help make the plot easier to read. Example 2.7. Graphing y = 4 + ln x and its local linear approximation f (x) ≈ x + 3 at (1, 4), in different colors, with keys. draw2d(yrange = [2,8], key = "4 + ln x", explicit(4 + log(x), x,0,5), key = "Local linear approximation", color = red, explicit(x + 3, x,0,5))$ Note the use of quotation marks. Unfortunately, the graph of y = x + 3 is in the way of the legend. We can fix this by restricting the horizontal plotting range of this line. You must execute load(draw)$ before using any draw command. Pg. 5 of 27 Example 2.8. Graphing y = 4 + ln x and its local linear approximation f (x) ≈ x + 3 at (1, 4), in different colors, with keys and space for the legend. draw2d(yrange = [2,8], key = "4 + ln x", explicit(4 + log(x), x,0,5), key = "Local linear approximation", color = red, explicit(x + 3, x,0,4))$ We can also add the point of tangency, and label it, too. Note that the point and its label are graphics objects. Example 2.9. Graphing y = 4 + ln x and its local linear approximation f (x) ≈ x + 3 at (1, 4), in different colors, with keys and space for the legend, and the point of tangency labeled. draw2d(yrange = [2,8], color = black, point_type = filled_circle, point_size = 1.6, points([[1,4]]), key = "4 + ln x", color = blue, explicit(4 + log(x), x,0,5), key = "Local linear approximation", color = red, explicit(x + 3, x,0,4), label_orientation = vertical, color = black, label(["Point of tangency", 1,5.2]))$ Note that the label itself is in quotation marks, followed by the x-coördinate and the y-coördinate of the center of the label. The point size option does not work if the point type is dot. Note to users of WindowsTM operating systems: As of 2013-09-23 there is a bug in draw that prevents labels from being other colors than blue, under some circumstances. There are other options we could use, but this is plenty good enough for now. 3 Conic sections and other implicitly defined curves Many conic sections—circles, ellipses, some parabolas, and most hyperbolas—are not functions. Often, they are defined implicitly. “Implicit” means that you haven’t solved for y yet, so your equation has x’s and y’s together on one side of the equals sign. If you solve for y, so that you have a function is in the form y = f (x), it’s called explicit. Here are the examples we saw when we were introduced to the explicit graphics object: Some implicitly defined functions: Some explicitly defined functions: xy = 1 y = 1/x x2 − y 2 = 1 y=x 2 y = −2x + 3 2x + y = 3 implicit graphics objects are for graphing implicitly defined curves. You must execute load(draw)$ before using any draw command. Pg. 6 of 27 Example 3.1. The unit circle x2 + y 2 = 1: draw2d(implicit(x^2 + y^2 = 1, x,-1.1,1.1, y,-1.1,1.1))$ Notice that you have to give both the range of x-values and the range of y-values to use. Doing so gives you control over the vertical plot range without having to use the yrange option. Also note that the unit “circle” appears a bit squashed. This can be fixed with the proportional axes option. Example 3.2. The unit circle x2 + y 2 = 1, with proportional axes set: draw2d(proportional_axes = xy, implicit(x^2 + y^2 = 1, x,-1.1,1.1, y,-1.1,1.1))$ Setting proportional axes to xy tells Maxima to use the same scale on the x-axis as on the y-axis. I actually recommend using the proportional axes option in most plots. Example 3.3. The astroid curve x2/3 + y 2/3 = 2: draw2d(proportional_axes = xy, implicit(x^(2/3) + y^(2/3) = 2, x,-3,3, y,-3,3))$ Graphics objects of any kinds can be combined in a single draw statement. Example 3.4. The astroid curve x2/3 + y 2/3 = 2 and the unit circle x2 + y 2 = 1: You must execute load(draw)$ before using any draw command. Pg. 7 of 27 draw2d(proportional_axes = xy, implicit(x^2 + y^2 = 1, implicit(x^(2/3) + y^(2/3) = 2, x,-3,3, y,-3,3))$ Example 3.0.1. An ellipse with its features labeled: draw2d(implicit((x-3)^2/4 + y^2/9 = 1, x,-1.5,7.5, y,-4,4), proportional_axes = xy, point_type = circle, point_size = 1.5, points([[3,0],[3,3],[3,-3],[1,0],[5,0], [3,sqrt(5)],[3,-sqrt(5)]]), color = black, label(["Center", 3,-0.4], ["Vertex 1", 3,3.4], ["Vertex 2", 3,-3.4], ["Subvertex 1", -0.2, 0], ["Subvertex 2", 6.2,0], ["Focus 1", 3,1.9], ["Focus 2", 3,-1.9]))$ (I had to fiddle with the locations of the labels a bit to get them to come out decently.) Implicit graphics objects can be used to get better graphs of some explicitly defined functions. Example 3.5. Graphing y = 4 + ln x as an explicit object and as an implicit object, in two separate plots, for comparison. draw2d(yrange = [0,8], explicit(4 + log(x), x,0,25))$ Compare the above plot with the following: You must execute load(draw)$ before using any draw command. Pg. 8 of 27 draw2d(implicit(4 + log(x), x,0,25, y,0,8))$ In the second plot, more of the curve is visible. This is an artifact of the way explicit graphics objects are constructed versus the way implicit objects are constructed. 4 Graphing parametric curves parametric graphics objects are for plotting curves that are defined parametrically. This means that instead of one formula with x and y in it, you have separate formulas for x and y, both given in terms of a third variable, usually s, t or θ. Example 4.1. The cycloid x = 3(t − sin t), y = 3(1 − cos t): draw2d(parametric(3*(t - sin(t)), 3*(1-cos(t)), t,-%pi/2, 5*%pi/2))$ Note that you have to tell Maxima the formula for x first, then the formula for y; then you have to give the range of t-values. Also note that this graph looks like it’s made of line segments. That’s because it is. All computer algebra systems plot curves by plotting points and then connecting the points with line segments. Sometimes, the graphs you get don’t look very good because Maxima doesn’t plot enough points. You can control the number of points that get plotted by using the nticks option. Example 4.2. The cycloid x = 3(t − sin t), y = 3(1 − cos t), with nticks = 50: draw2d(nticks = 50, parametric(3*(t - sin(t)), 3*(1-cos(t)), t,-%pi/2, 5*%pi/2))$ You must execute load(draw)$ before using any draw command. Pg. 9 of 27 Using a larger vertical range will make the plot easier to read. Example 4.3. The cycloid x = 3(t − sin t), y = 3(1 − cos t), with nticks = 50 and a slightly larger vertical plotting range: draw2d(nticks = 50, yrange = [-1,7] parametric(3*(t - sin(t)), 3*(1-cos(t)), t,-%pi/2, 5*%pi/2))$ Here’s another parametric curve: a tractrix, which describes the path of an object being dragged behind another object. Example 4.4. The tractrix x = t − 2 tanh 2t , y = 2 sech 2t : draw2d(parametric(t - 2*tanh(t/2), 2*sech(t/2), t,-8,8))$ 5 Polar coördinates polar graphics objects are for graphing in polar coördinates. To use a polar graphics object, your equation has to be in the form r = f (θ), that is, you have to solve for r. Example 5.1. The logarithmic spiral ln r = θ : First, solve for r to get r = eθ/2 . Then proceed to graph. 2 draw2d(polar(%e^(%theta/2), %theta,0,2*%pi))$ Note that the spiral seems to be made up of line segments. Actually, all the curves you plot in any computer algebra system are made up of line segments. Use the nticks option to make the curve smoother. While you’re at it, use the proportional axes option to get a better feel for the true shape of the curve. You must execute load(draw)$ before using any draw command. Pg. 10 of 27 Example 5.2. The logarithmic spiral ln r = θ , with nticks = 100 and with proportional axes set: 2 draw2d(nticks = 100, proportional_axes = xy, polar(%e^(%theta/2), %theta,0,2*%pi))$ Example 5.3. The three-petal rose r = 2 cos 3θ: draw2d(polar(2*cos(3*%theta), %theta,0,%pi))$ This looks pretty bad. The rose is a smooth curve, not this blocky thing. If you’re in one of my classes, don’t turn in graphs that look like this. Use the nticks option to make the curve look smoother. Example 5.4. The three-petal rose r = 2 cos 3θ, with nticks = 75 and with proportional axes set: draw2d(nticks = 75, proportional_axes = xy, polar(2*cos(3*%theta), %theta,0,2*%pi))$ This graph is fit to turn in. 6 Cylinders Not all cylinders are created equal. Some can be plotted as explicit objects. Some cannot; fortunately, these can be plotted as implicit objects. Some of the options you’ve used in 2-dimensional plots can be used in the same way, in 3-dimensional plots. Others can be used, but not in the same way. Some can’t be used in 3D, and there are options that work in 3D but not 2D. Some of the options I use more commonly are discussed in the examples of this section. Others can be found in Section 15. You must execute load(draw)$ before using any draw command. Pg. 11 of 27 6.1 Cylinders and explicit objects The equations of some cylinders can be treated in Maxima as explicit objects. An example is z = x2 . Note that z appears only on one side of the equals sign, is all by itself, and appears only to the first power. This means z is defined explicitly. Any time you have an equation that defines z explicitly in terms of x or y or both, you can use an explicit object to plot it. Example 6.1.1. The parabolic cylinder z = x2 : draw3d(proportional_axes = xy, explicit(x^2, x,-3,3, y,-3,3))$ Note that you have to supply the ranges of values for both x and y. Also note that I started with the proportional axes option set to xy. I just like my plots “squared up.” The rightmost part of the graph isn’t clear. That’s because the graph is transparent. To make it opaque, you can use the surface hide option. Example 6.1.2. The parabolic cylinder z = x2 , with surface hide = true: draw3d(proportional_axes = xy, surface_hide = true, explicit(x^2, x,-3,3, y,-3,3))$ Rotate the graph to get a better idea of what the cylinder looks like, and to see more clearly the effect of the surface hide option. If you prefer a different color, you can use the color option exactly as you did with draw2d. Example 6.1.3. The parabolic cylinder z = x2 , in green, with surface hide = true: draw3d(proportional_axes = xy, surface_hide = true, color = green, explicit(x^2, x,-3,3, y,-3,3))$ Many people appreciate having the plot color-coded in various ways. The easiest way is to use the enhanced3d option. Setting enhanced3d = true color-codes the points of the plot according to their zvalues. You must execute load(draw)$ before using any draw command. Pg. 12 of 27 Example 6.1.4. The parabolic cylinder z = x2 , with enhanced3d = true: draw3d(proportional_axes = xy, enhanced3d = true, explicit(x^2, x,-3,3, y,-3,3))$ Note that the enhanced3d option includes surface hide = true. It also ignores the color option. You may wonder if you can also make the scale on the z-axis to be the same as the scale on the x- and y-axes. You can, but it often doesn’t do much good. (Example: If you plot z = 100x2 + 400xy + 100y 2 with all three axes having the same scale, you will need either a very tall computer screen or a magnifying glass!) Example 6.1.5. The parabolic cylinder z = x2 , with enhanced3d = true and proportional axes = xyz: draw3d(proportional_axes = xyz, enhanced3d = true, explicit(x^2, x,-3,3, y,-3,3))$ Example 6.1.6. The parabolic cylinder z = x2 , with enhanced3d = true, proportional axes = xyz, and the x, y-plane drawn at z = 0: draw3d(proportional_axes = xyz, xyplane = 0, enhanced3d = true, explicit(x^2, x,-3,3, y,-3,3))$ Here’s the roof of a Quonset hut. Example 6.1.7. The cylinder z = 8 − cosh x, with enhanced3d = true, proportional axes = xyz, and the x, y-plane drawn at z = −3: You must execute load(draw)$ before using any draw command. Pg. 13 of 27 draw3d(enhanced3d=true, proportional_axes = xy, xyplane = -3, explicit(8 - cosh(x), x,-3.1,3.1, y,-3,3))$ You can put multiple graphics objects in your 3D plot, just as you did in the 2D case. Example 6.1.8. The parabolic cylinders z = x2 and z = 5 − y 2 , with enhanced3d = true and proportional axes = xy: draw3d(proportional_axes = xy, enhanced3d = true, explicit(5 - y^2, x,-3,3, y,-3,3), explicit(x^2, x,-3,3, y,-3,3))$ Now, if the point is to see the intersection between the surfaces, you may prefer to see the plot without the enhanced3d option. I recommend using the surface hide option, instead. I also recommend using different colors for the surfaces, so as to make the curve of intersection easier to see. Example 6.1.9. The parabolic cylinders z = x2 and z = 5−y 2 , in different colors, with proportional axes = xyz: draw3d(proportional_axes = xy, explicit(5 - y^2, x,-3,3, y,-3,3), color = red, explicit(x^2, x,-3,3, y,-3,3))$ Try rotating this graph, to get a better feel for the shape of the intersection between the two cylinders. 6.2 Cylinders and implicit objects Many cylinders are expressed by means of implicit equations. Others are given by explicit equations that nevertheless cannot be plotted using the explicit object, such as y = z 2 . (This is because z is not the isolated variable. Maxima’s explicit object assumes you’ve solved for z.) The way around this is to use an implicit graphics object, instead. You must execute load(draw)$ before using any draw command. Pg. 14 of 27 Example 6.2.1. The circular cylinder x2 + y 2 = 4, with enhanced3d = true and proportional axes = xyz: draw3d(proportional_axes = xyz, enhanced3d = true, implicit(x^2 + y^2 = 4, x,-3,3, y,-3,3, z,-3,3))$ Note that you have to supply the range of z-values, as well. Example 6.2.2. The elliptical cylinder x2 /4 + y 2 = 4, in a nice green color, with surface hide = true and proportional axes = xyz: draw3d(surface_hide=true, proportional_axes = xyz, color=forest-green, implicit(x^2/4 + y^2=4, x,-5,5, y,-3,3, z,-3,3))$ Example 6.2.3. The hyperbolic cylinder z 2 − y 2 = 1, with enhanced3d = true and proportional axes = xyz: draw3d(proportional_axes = xyz, enhanced3d = true, implicit(x^2 - y^2 = 1, x,-3,3, y,-3,3, z,-3,3))$ The plane x = y is a cylinder than cannot be plotted as an explicit object, because the equation has not been solved for z. (Solving for z is quite impossible, because z is not in the equation!) Example 6.2.4. The plane x = y, with enhanced3d = true and proportional axes = xyz: You must execute load(draw)$ before using any draw command. Pg. 15 of 27 draw3d(enhanced3d=true, proportional_axes = xyz, xyplane = -3, implicit(x = y, x,-3,3, y,-3,3, z,-3,3))$ 7 Quadric surfaces Like cylinders, some quadric surfaces are given explicitly and some are given implicitly. Note that x = y 2 −z 2 is a perfectly good explicit equation, but we can’t plot it with an explicit object, because z is not the isolated variable. That’s OK; we can use an implicit object, instead. 7.1 Quadric surfaces and explicit objects Here’s an elliptic paraboloid that can be plotted using an explicit graphics object. Example 7.1.1. The elliptic paraboloid z = x2 + y 2 /4, with enhanced3d = true and proportional axes = xyz: draw3d(proportional_axes = xy, enhanced3d = true, explicit(x^2 + y^2/4, x,-3,3, y,-3,3))$ The following hyperbolic paraboloid can also be plotted using an explicit graphics object. Example 7.1.2. The hyperbolic paraboloid z = x2 −y 2 , with enhanced3d = true and proportional axes = xyz: draw3d(proportional_axes = xy, enhanced3d = true, explicit(x^2 - y^2, x,-3,3, y,-3,3))$ You must execute load(draw)$ before using any draw command. Pg. 16 of 27 7.2 Quadric surfaces and implicit objects Most quadric surfaces are best plotted by using implicit objects, either because they are implicitly defined or because z is not the isolated variable. Example 7.2.1. The ellipsoid x2 + y 2 + z 2 /4 = 1, with enhanced3d = true and proportional axes = xyz: draw3d(proportional_axes = xyz, xyplane = 0, enhanced3d = true, implicit(x^2 + y^2 + z^2/4 = 1, x,-1.5,1.5, y,-1.5,1.5, z,-2.5,2.5))$ This ellipsoid looks a little rough. Use the x voxel, y voxel, and z voxel options to smooth it out. A “voxel” is a “volume picture element.” In other words, it’s one of the tiny little dots on your computer screen that make up pictures. The default value of x voxel is 10. I think “10” means that Maxima divides the x-axis into 10 segments, therefore using 11 x-coördinates for the points it seeks to plot. If you set x voxel to a higher value than 10, Maxima will divide the x-axis into smaller pieces, and will therefore plot more points. y voxel and z voxel behave the same way. When 10 isn’t high enough for me, I usually try 15. I’ve tried more than that, but settings higher than 25 never seem to help any more than 20. Anyway, here’s a smoother version of the same ellipsoid. Example 7.2.2. The ellipsoid x2 + y 2 + z 2 /4 = 1, with enhanced3d = true, proportional axes = xyz, and x voxel, y voxel, and z voxel all set equal to 15: draw3d(proportional_axes = xyz, xyplane = 0, enhanced3d = true, x_voxel = 15, y_voxel = 15, z_voxel = 15, implicit(x^2 + y^2 + z^2/4 = 1, x,-1.5,1.5, y,-1.5,1.5, z,-2.5,2.5))$ Example 7.2.3. The elliptic paraboloid x = y 2 + z 2 /4, with enhanced3d = true and proportional axes = xyz: draw3d(proportional_axes = xyz, xyplane = -3, enhanced3d = true, implicit(x = y^2 + z^2/4, x,-1,2, y,-1.5,1.5, z,-3,3))$ You must execute load(draw)$ before using any draw command. Pg. 17 of 27 Example 7.2.4. The elliptic paraboloid x = y 2 + z 2 /4 again, this time with enhanced3d = true and proportional axes = xyz, and with x voxel, y voxel, and z voxel all set equal to 15: draw3d(proportional_axes = xyz, xyplane = -3, enhanced3d = true, x_voxel = 15, y_voxel = 15, z_voxel = 15, implicit(x = y^2 + z^2/4, x,-1,2, y,-1.5,1.5, z,-3,3))$ Example 7.2.5. The hyperbolic paraboloid x = y 2 −z 2 /4, with enhanced3d = true and proportional axes = xyz, and with x voxel, y voxel, and z voxel all set equal to 15: draw3d(proportional_axes = xyz, xyplane = -3, enhanced3d = true, x_voxel = 15, y_voxel = 15, z_voxel = 15, implicit(x = y^2 - z^2/4, x,-2,2, y,-2,2, z,-2.5,2.5))$ Example 7.2.6. The hyperboloid of one sheet x2 −y 2 +z 2 = 1, with enhanced3d = true and proportional axes = xyz, and with x voxel, y voxel, and z voxel all set equal to 15: draw3d(proportional_axes = xyz, xyplane = -3, enhanced3d = true, x_voxel = 15, y_voxel = 15, z_voxel = 15, implicit(x^2 - y^2 + z^2 = 1, x,-2.5,2.5, y,-2,2, z,-2.5,2.5))$ Example 7.2.7. The hyperboloid of two sheets −x2 /2 + y 2 − z 2 /4 = 1, with enhanced3d = true and proportional axes = xyz, and with x voxel, y voxel, and z voxel all set equal to 15: draw3d(proportional_axes = xyz, xyplane = 0, enhanced3d = true, x_voxel = 15, y_voxel = 15, z_voxel = 15, implicit(-x^2/2 + y^2 -z^2/4 = 1, x,-2,2, y,-1.5,1.5, z,-2.5,2.5))$ You must execute load(draw)$ before using any draw command. Pg. 18 of 27 8 Vectors in 2 and 3 dimensions Use the vector graphics object for plotting vectors. The default length of the head of the vector is 2 x-axis units. This is fine when your vectors are long, but for shorter vectors, it needs changing. 8.1 Vectors in 2 dimensions 1 Example 8.1.1. The vector , in standard position, plotted with all the default settings. (“Standard 2 position” means the tail is on the origin.) draw2d(vector([0,0], [1,2]))$ That big blue patch is the head of the vector (or, what we can see of the head in this plot window). A quick bit of trial-and-error leads to the much nicer head size 0.03. 1 Example 8.1.2. The vector , in standard position, with head length = 0.03. 2 draw2d(head_length = 0.03, vector([0,0], [1,2]))$ Now we can see that the tail is on the origin, so that the vector is in standard position. The head of the vector is the blue spot in the upper right-hand corner of the plot. It’s too wide for my tastes. You can change the width of the head of the vector with the head angle option. The angle is measured in degrees. 1 Example 8.1.3. The vector , in standard position, with head length = 0.03 and head angle = 25. 2 draw2d(head_angle = 25, head_length = 0.03, vector([0,0], [1,2]))$ You must execute load(draw)$ before using any draw command. Pg. 19 of 27 Now that we have a relatively nice-looking vector, let’s square up the axes. 1 Example 8.1.4. The vector , in standard position, with options as before, and with proportional axes 2 set. draw2d(proportional_axes = xy, head_angle = 25, head_length = 0.03, vector([0,0], [1,2]))$ Hmm. . . The plot window has been scaled to the size of the vector. Let’s change the x- and y-ranges to something more comfortable. 1 Example 8.1.5. The vector , in standard position, with all the options as before, and with the x- and 2 y- ranges set manually. draw2d(proportional_axes = xy, xrange = [-3,3], yrange = [-3,3], head_angle = 25, head_length = 0.03, vector([0,0], [1,2]))$ That’s better, except now the head is too small. (It’s only 0.03 x-axis units wide, after all.) 1 Example 8.1.6. The vector , as before, with a somewhat larger head. 2 draw2d(proportional_axes = xy, xrange = [-3,3], yrange = [-3,3], head_angle = 25, head_length = 0.1, vector([0,0], [1,2]))$ What about vectors that are not in standard position? Well, in the statement vector([0,0], [1,2]), change the [0,0] to the point where you want the tail to be. 1 Example 8.1.7. Four copies of the vector , with all the options as before (except a slightly larger plot 2 window). You must execute load(draw)$ before using any draw command. Pg. 20 of 27 draw2d(xrange = [-3.5,3.5], yrange = [-3.5,3.5], proportional_axes = xy, head_angle = 25, head_length = 0.1, vector([0,0], [1,2]), color = red, vector([2,1],[1,2]), color = forest-green, vector([-1,-1],[1,2]), color = salmon, vector([-2,0],[1,2]))$ 8.2 Vectors in 3d You can plot vectors in three dimensions much as you do in two. Of course, you use draw3d or wxdraw3d for this, and you have a zrange option. And recall that if you set proportional axes = xyz, then you may have to use the xyplane option, as we did in Section 6.1. 1 Example 8.2.1. The vector 2 , with all my favorite options. −3 draw3d(proportional_axes = xyz, xrange = [-3.5,3.5], yrange = [-3.5,3.5], zrange = [-3.5,3.5], xyplane = -3, head_angle = 25, head_length = 0.1, vector([0,0,0], [1,2,-3]))$ 1 Example 8.2.2. Four copies of the vector 2 , with all my favorite options. −3 draw3d(proportional_axes = xyz, xrange = [-3.5,3.5], yrange = [-3.5,3.5], zrange = [-3.5,3.5], xyplane = -3, head_angle = 25, head_length = 0.1, vector([0,0,0], [1,2,-3]), color = red, vector([2,1,0],[1,2,-3]), color = forest-green, vector([-1,-1,2],[1,2,-3]), color = salmon, vector([-2,0,1],[1,2,-3]))$ You really have to rotate this plot to appreciate it. You must execute load(draw)$ before using any draw command. Pg. 21 of 27 9 Lines and curves in space Plotting lines and curves in space requires the parametric graphics object. In these examples, I’ll go ahead and use a few options that should be familiar to you by now. (If they aren’t, look at other examples in this document to see why and how they are used.) 9.1 Lines x = 2t + 1 Example 9.1.1. The line y = t − 3 , with a few handy options. z = t/2 draw3d(proportional_axes = xyz, xyplane = -3, parametric(2*t + 1, t-3, t/2, t,-3,3))$ Putting two lines in the same x Example 9.1.2. The lines y z plot can help you = 2t + 1 x = t − 3 and y z = t/2 decide whether they intersect or not. = 2t + 1 = t − 3 , with a few handy options. = t/2 draw3d(proportional_axes = xyz, xyplane = -3, parametric(2*t+1, t-3, t/2, t,-3,3), color = red, parametric(-t+2, 3t-1, 2t))$ Rotate this plot, and convince yourself that the lines do not intersect. 9.2 Curves Curves can be plotted parametrically, just as lines can. Example 9.2.1. The basic helix [cos t, sin t, t]T . You must execute load(draw)$ before using any draw command. Pg. 22 of 27 draw3d(nticks=500, parametric(cos(t),sin(t),t, t,-5,5))$ Example 9.2.2. A spiral on a cone. draw3d(nticks=500, parametric((1-t)*cos(3*%pi*t), (1-t)*sin(3*%pi*t), t, t,-5,5))$ Example 9.2.3. A 3D version of a Lissajous curve. draw3d(nticks=500, xrange = [-3.1,3.1], yrange = [-3.1, 3.1], parametric(3*cos(t),sin(t),sin(2*t), t,-5,5))$ Example 9.2.4. A Celtic knot, with a few handy options. draw3d(nticks=500, xrange = [-3.1,3.1], yrange = [-3.1, 3.1], parametric(3*cos(3*t),2*cos(5*t),sin(7*t), t,-%pi,%pi))$ Drag this plot with your mouse to see it from different angles. If you don’t think this curve is cool, then I can’t help you! There’s a point to showing you several examples without explaining them. In particular, by now you should be able to read the code well enough to notice things like the following: To get decent-looking curves, I didn’t have to use all the options I normally use. You must execute load(draw)$ before using any draw command. Pg. 23 of 27 Exercise for the diligent student: Experiment with options like proportional axes, etc. on the examples in this section. That will help you get a better feel for what the options do. 10 More about surfaces The graph of a function z = f (x, y) is a surface. In fact, such a surface can be plotted using an explicit graphics object. There are a couple of options I’d like to share with you. 11 Cylindrical coördinates To appear . . . 12 Spherical coördinates To appear . . . 13 Parametric surfaces To appear . . . 14 Vector fields To appear . . . 15 More about options This section offers more detail about options mentioned elsewhere in this document. It also describes some additional options and how to simplify the repeated use of a set of options. 15.1 color wxMaxima’s default color for graphs is blue. If you want to change the color, use the color option. There are many predefined colors. See the document Graphics in the wxMaxima GUI, on my faculty website, for methods to use other colors besides the predefined ones. You have to realize that any given color may look different on different computer screens. This is not the fault of Maxima; it has to do with how the hardware renders colors.2 Example 15.1.1. y = 4 + ln x in red: draw2d(color = red, explicit(4 + log(x), x,0,25))$ 2 In particular, the “color temperature” can often be easily adjusted, and can really make a difference in the colors you see. You must execute load(draw)$ before using any draw command. Pg. 24 of 27 Example 15.1.2. y = ex sin x in black: draw2d(color = black, explicit(%e^x*sin(x), x,-3,3))$ Example 15.1.3. Four different logarithmic curves: draw2d(color = blue, explicit(4 + log(x), color = forest_green, explicit(2 + log(x), color = salmon, explicit(log(x), color = goldenrod, explicit(-2 + log(x), x,0,25), x,0,25), x,0,25), x,0,25))$ The predefined colors are: white black gray0 grey0 gray10 grey10 gray20 grey20 gray30 grey30 gray40 grey40 gray50 grey50 gray60 grey60 gray70 grey70 gray80 grey80 gray90 grey90 gray100 grey100 gray grey light-gray light-grey dark-gray dark-grey red light-red dark-red yellow light-yellow dark-yellow green light-green dark-green spring-green forest-green sea-green blue light-blue dark-blue midnight-blue navy medium-blue royalblue skyblue cyan light-cyan dark-cyan magenta light-magenta dark-magenta turquoise light-turquoise dark-turquoise pink light-pink dark-pink coral light-coral orange-red salmon light-salmon dark-salmon aquamarine khaki dark-khaki goldenrod light-goldenrod dark-goldenrod gold beige brown orange dark-orange violet dark-violet plum purple To be continued. . . 15.2 Repeated use of the same options You will eventually find that there are options you like to use a lot, such as proportional axes or enhanced3d. Fortunately, there is a way to use your favorite options in lots of graphics, without having to re-type or copy-and-paste them over and over: Use the set draw defaults command. You must execute load(draw)$ before using any draw command. Pg. 25 of 27 The following example makes the following values the default settings of the indicated options: 1. New default range of x-values: [−3, 3] 2. New default range of y-values: [−3, 3] 3. New default axis scaling: x- and y-axes have the same scale 4. Make Maxima put the x, y-plane of the plot at z = 0 by default, from now on 5. Turn on enhanced3d mode from now on, by default 6. New default value for each of x voxel, y voxel, and z voxel: 15 set_draw_defaults(xrange = [-3,3], yrange = [-3,3], proportional_axes = xyz, xyplane = 0, enhanced3d = true, x_voxel = 15, y_voxel = 15, z_voxel = 15)$ The above values will be used by default until you change the defaults again, or until you end your Maxima session, whichever comes first. To restore the original defaults, use set draw defaults(), with nothing in the parentheses. Example 15.2.1. An ellipsoid, using the defaults that are set by the set draw defaults in the previous paragraph, followed by the same graphic made after restoring the original defaults. draw3d(proportional_axes = xyz, implicit(z^2/7+y^2/5+x^2/3=1, x,-3,3, y,-3,3, z,-3,3))$ For some reason I haven’t been able to figure out, on my system I get perfectly good graphics with these defaults, until I try to save such graphics. I’ll take care of this another time. Now restoring the original defaults and repeating the plot: set_draw_defaults()$ draw3d(proportional_axes = xyz, implicit(z^2/7+y^2/5+x^2/3=1, x,-3,3, y,-3,3, z,-3,3))$ Of course, the point of changing the defaults is to use the desired options for lots of graphs during your Maxima session. In the above example, we only did one graph. You must execute load(draw)$ before using any draw command. Pg. 26 of 27 16 Saving your graphs Suppose you make a graphic for a homework assignment, and you want to be able to put it in a word processing document, or something. You can save it in any one of several formats: .jpg, .png, .ps, .pdf, and others. For graphics for a typical math course, I recommend .png over .jpg, unless your graphic uses shading to give a 3-dimensional effect. To store a graphic, you need two additional options in your draw command: file name and terminal. The file name is the name of the file to which the graphic is to be saved. By default, the graphic is saved in Maxima’s working directory. If you want it in some other directory, use the full pathname of the file. Warning: The file name must be enclosed in double quotes. terminal is the file format you want to use. Warning: The file format must be preceded by an apostrophe. Warning: Maxima does not like file names that have spaces in them. So if you’re using Windows, you’ll need to create a directory somewhere other than in My Documents, in which to store your graphics. Example: C:\Maxima Graphics. Example 16.1. y = 4 + ln x saved as a .png file, on a Windows machine: draw2d(file_name = "C:\Maxima_Graphics\4-plus-log-x", terminal = ’.png, explicit(4 + log(x), x,0,25))$ Example 16.2. y = ex sin x saved as a .jpg file on a Linux machine: draw2d(file_name = "/home/Brown/Documents/Math/Maxima_Graphics/e-to-x-times-sine-x", terminal = ’.jpg, explicit(%e^x*sin(x), x,-3,3))$ You must execute load(draw)$ before using any draw command. Pg. 27 of 27