Graphics Programs Reference
In-Depth Information
4
3
2
1
0
-1
-2
-3
-4
2
1
2
1
0
0
-1
-1
-2
-2
Figure5-6
WiththeSymbolicMathToolbox,thereisashortcutcommand
ezmesh
,
and you can obtain a result very similar to Figure 5-6 with
>> ezmesh('xˆ2 - yˆ2', [-2, 2], [-2, 2])
If one wants to plot a surface that cannot be represented by an equation
of the form
z
=
f
(
x
,
y
), for example the sphere
x
2
+
y
2
+
z
2
=
1, then it is bet-
ter to parameterize the surface using a suitable coordinate system, in this
case cylindrical or spherical coordinates. For example, we can take as param-
eters the vertical coordinate
z
and the polar coordinate
θ
in the
x
-
y
plane. If
r
denotes the distanc
e to th
e
z
axis, then
the eq
uation of th
e sphe
re becomes
r
2
=
1, or
r
=
√
1
−
z
2
, and so
x
=
√
1
−
z
2
cos
θ
,
y
=
√
1
−
z
2
sin
θ
. Thus
we can produce our plot with
+
z
2
>> [theta, Z] = meshgrid((0:0.1:2)*pi, (-1:0.1:1));
>> X = sqrt(1 - Z.ˆ2).*cos(theta);
Search WWH ::
Custom Search