Page 38 - Basics of MATLAB and Beyond
P. 38

We can plot the surface z as a function of x and y:





                               mesh(x,y,z)





                                  We can expand the domain of the calculation by increasing the input
                               to meshgrid. Be careful to end the lines with a semicolon to avoid being
                               swamped with numbers:



                               [x,y] = meshgrid(-10:10);
                               z = sqrt(x.^2 + y.^2);
                               mesh(x,y,z)




                               The surface is an inverted cone, with its apex at (0, 0, 0).
                                    Companion M-Files Feature 3 A clearer plot can be produced
                                    using a polar grid, instead of a rectilinear grid. We can use the
                                    companion function polarmesh to produce such a plot. First we
                                    define a polar grid of points:

                                    [r,th] = meshgrid(0:.5:10,0:pi/20:2*pi);
                                    Then display the surface defined by z = r:






                                    polarmesh(r,th,r)






                               A more interesting surface is
                                                                                2
                                                 2 −x −(y+1)
                                                                 1
                                                                       3
                                                                           5
                                      z = 3(1 − x) e  2    2  − 10( x − x − y )e −x −y  2  ···
                                                                 5
                                           1 −(x+1) −y
                                         − e       2  2  .
                                           3
                               In matlab notation you could type:
                               c   2000 by CRC Press LLC
   33   34   35   36   37   38   39   40   41   42   43