Page 48 - Numerical Analysis Using MATLAB and Excel
P. 48
Summary
• MATLAB has no default color; it starts with blue and cycles through seven colors. Also, there
is no default marker; no markers are drawn unless they are selected. The default line is the
solid line.
•The plot3(x,y,z) command plots a line in 3−space through the points whose coordinates are
the elements of , , and , where x, y, and z are three vectors of the same length.
xy
z
y
x
•In a two−dimensional plot, we can set the limits of the − and −axes with the axis([xmin
xmax ymin ymax]) command. Likewise, in a three−dimensional plot we can set the limits of
all three axes with the axis([xmin xmax ymin ymax zmin zmax]) command. It must be
placed after the plot(x,y) or plot3(x,y,z) commands, or on the same line without first execut-
ing the plot command. This must be done for each plot. The three−dimensional
,,
text(x,y,z,’string’) command will place string beginning at the co−ordinate (xy z ) on the
plot.
•The mesh(x,y,z) command displays a three−dimensional plot. Another command, con-
tour(Z,n), draws contour lines for n levels. We can also use the mesh(x,y,z) command with
two vector arguments. These must be defined as length x() = n and length y() = m
where mn,[ ] = size Z() . In this case, the vertices of the mesh lines are the triples
{ xj() yi() Zi j } , , ( , ) . We observe that x corresponds to the columns of , and y corresponds to
Z
,
Z
(
the rows of . To produce a mesh plot of a function of two variables, say z = f x y ) , we must
Y
X
first generate the and matrices which consist of repeated rows and columns over the
x
X
Y
y
range of the variables and . We can generate the matrices and with the [X,Y]=mesh-
grid(x,y) function which creates the matrix whose rows are copies of the vector x, and the
X
Y
matrix whose columns are copies of the vector y.
• MATLAB can display up to four windows of different plots on the Figure window using the
command subplot(m,n,p). This command divides the window into an mn matrix of plotting
×
areas and chooses the pth area to be active.
• With MATLAB, matrix multiplication (multiplication of row by column vectors) is performed
with the matrix multiplication operator (*), whereas element−by−element multiplication is
performed with the dot multiplication operator (.*). Similarly, the division (/) and exponentia-
tion (^) operators, are used for matrix division and exponentiation, whereas dot division (./)
and dot exponentiation (.^) are used for element−by−element division and exponentiation.
• To avoid division by zero, we use the special MATLAB function eps, which is a number
approximately equal to 2.2 10 – 16 .
×
• The command axis([xmin xmax ymin ymax]) scales the current plot to the values specified
by the arguments xmin, xmax, ymin and ymax. There are no commas between these four
arguments. This command must be placed after the plot command and must be repeated for
each plot.
Numerical Analysis Using MATLAB® and Excel®, Third Edition 1−35
Copyright © Orchard Publications