A First Surface Plot in Mathematica

Copyright © 1997 by James F. Hurley, University of Connecticut, Department of Mathematics, U-9, Storrs CT 06269-3009.  All rights reserved.

Mathematica's built-in Plot3D command is a good tool for plotting a surface that is the graph of z = f(x, y), for a continuous function f. The  following short routine illustrates this for the graph of z = [Graphics:Images/FirstSurf_gr_1.gif]+ 4. As usual, to generate the plot, position the cursor at the end of the last blue line, and press the Enter key, or depress the Shift key and the Return key simultaneously.

                 (* Mathematica Routine to plot graph of a
                 surface
z = f(x, y) *)    
  
          F[x_, y_] := y^2 + 4;
            Plot3D[ F[x, y], {x, -3, 3}, {y, -3, 3},
                    AxesLabel -> {"x", "y", "z"} ]      

[Graphics:Images/FirstSurf_gr_2.gif]

    
   The following more elaborate routine first generates the same plot that the above routine produces, and then gives a second plot with coordinate axes (in red). In using this routine to make your own plots, some adjustment of the input intervals [a, b] along the x-axis, [c, d] along the y-axis, and [e, f] along the z-axis may be necessary to produce a good plot and worthwhile axes. To do that, change the part of the routine that draws the coordinate axes.

         (* Mathematica Routine to plot graph of a surface   
      
z = f(x, y), with coordinate axes drawn in red *)
          

    
a := -3;
    b := 3;
    c := -3;
    d := 7;
    e := -9;
    f := 10;

    
F[x_, y_] := y^2 + 4
    plainplot = Graphics3D[
                 Plot3D[ F[x, y], {x, -3, 3}, {y, -3, 3},
                         AxesLabel -> {"x", "y", "z"} ]
                                  ];
    coordaxes = Graphics3D[{
                            {RGBColor[1, 0, 0],
                             Line[{{a, 0, 0}, {b, 0, 0}}],
                             Text["x", {b + .3, 0, 0}]},
                            {RGBColor[1, 0, 0],
                             Line[{{0, c, 0}, {0, d, 0}}],
                             Text["y", {0, d + 1, 0}]},
                            {RGBColor[1, 0, 0],
                             Line[{{0, 0, e}, {0, 0, f}}],
                             Text["z", {0, 0, f + 5}]}
                             }];              
         Show[plainplot, coordaxes]
                        

[Graphics:Images/FirstSurf_gr_3.gif]


Converted by Mathematica      September 28, 2001