Visualizing Functions of Two Variables
The first step in displaying a function of two variables, z = f(x,y), is to generate
Y matrices consisting of repeated rows and columns, respectively, over the domain of the function. Then use these matrices to evaluate and graph the function.
meshgrid function transforms the domain specified by two vectors,
y, into matrices
Y. You then use these matrices to evaluate functions of two variables. The rows of
X are copies of the vector
x and the columns of
Y are copies of the vector
To illustrate the use of
meshgrid, consider the
sinc function. To evaluate this function between -8 and 8 in both x and y, you need pass only one vector argument to
meshgrid, which is then used in both directions.
R contains the distance from the center of the matrix, which is the origin. Adding
eps prevents the divide by zero (in the next step) that produces
Inf values in the data.
sinc function and plotting
mesh results in the 3-D surface.
Emphasizing Surface Shape
MATLAB provides a number of techniques that can enhance the information content of your graphs. For example, this graph of the
sinc function uses the same data as the previous graph, but employs lighting and view adjustment to emphasize the shape of the graphed function (
surf function for more information on surface plots.
|Mesh and Surface Plots||Surface Plots of Nonuniformly Sampled Data|
© 1994-2005 The MathWorks, Inc.