10.2 Mesh and Surface Plots 327
Once the three matrices have been created, they can be used to plot mesh or sur-
face plots.
Making mesh and surface plots:
A mesh or surface plot is created with the mesh or surf command, which has
the form:
where X and Y are matrices with the coordinates of the grid and Z is a matrix with
the value of
z at the grid points. The mesh plot is made of lines that connect the
points. In the surface plot, areas within the mesh lines are colored.
As an example, the following script file contains a complete program that
creates the grid and then makes a mesh (or surface) plot of the function
over the domain and .
Note that in the program above the vectors x and y have a much smaller spacing
than the spacing earlier in the section. The smaller spacing creates a denser grid.
The figures created by the program are:
Z =
-0.5000 0 0.5000 0.4000 0.3000
-0.8000 0 0.8000 1.0000 0.9231
-0.9000 0 0.9000 1.3846 1.5000
-0.9412 0 0.9412 1.6000 1.9200
x=-1:0.1:3;
y=1:0.1:4;
[X,Y]=meshgrid(x,y);
Z=X.*Y.^2./(X.^2+Y.^2);
mesh(X,Y,Z)
xlabel('x'); ylabel('y'); zlabel('z')
z
xy
2
x
2
y
2
+
----------------=
Type surf(X,Y,Z) for surface plot.
评论0