
functional expression, z=f(x,y), is evaluated. Usually, we evaluate the z
behavior in a certain area of the (x,y)-plane in which z has some interesting
properties (e.g. it presents a minimum, a maximum or a saddle point).
Suppose that a
x
x vector that defines the x-axis (abscissa) and a
y
y vector that
defines the y-axis (ordinate) exist and define the (x,y)-plane on which we
would like to create the 3D surface of z=f(x,y). To plot the surface, it is
needed to create a grid of sample points (most preferable with high density
and this is defined by the difference between the elements of
x
x and
y
y) that
covers the rectangular domain of the (x,y) plane in order to generate
X
X and
Y
Y
matrices consisting of repeated rows and columns of
x
x and
y
y, respectively,
over the domain of the function. Then these matrices will be used to
evaluate and graph the function.
The
m
m
e
e
s
s
h
h
g
g
r
r
i
i
d
d function transforms the domain specified by two vectors,
x
x
and
y
y, into matrices,
X
X and
Y
Y. You then use these matrices to evaluate the
z=f(x,y). The rows of
X
X are copies of the vector
x
x and the columns of
Y
Y are
copies of the vector
y
y.
We will see how we can plot a 3D surface via an example. Let say that we
need a graph of the well know peaks function that has the following
functional form:
222222
15312
1
1013
y)x(yx)y(x
ee)yx
x
(e)x()y,x(fZ
−+−−−+−−
−−−−−==
We want to examine this function in the rectangular space of (x,y)-plane
defined as:
44
≤≤−
y
x
Since Matlab understands combinations of (x,y,z) pairs only, it is needed to
evaluate
Z
Z at various points (the number of these points defines the surface
smoothness) that lay in the above rectangular space.
m
m
e
e
s
s
h
h
g
g
r
r
i
i
d
d can be used
to create the desired grid of points. The following code lead to the generation
of the grid:
Komentáře k této Příručce