© 2001 by CRC Press LLC
1. To evaluate the function for a speciFed value
x=x1
, enter
aline(x1)
to get the function value
at this point; that is,
y
1
= 3
x
1
– 5.
2. To plot
y
1
= 3
x
1
– 5 for a range of
x
values, say [–2, 7], enter:
fplot('aline',[-2,7])
NOTE
The above example illustrates a function with one input and one out-
put. The construction of a
function
M-Fle
of a function having
n
inputs and
m
outputs starts with:
function [y1,y2,.
..,ym]=funname(x1,x2,.
..,xn)
Above, using a
function M-Fle,
we showed a method to plot the deFned
function
aline
on the interval (–2, 7) using the
fplot
command. An alter-
native method is, of course, to use arrays, in the manner speciFed in Chapter
1. SpeciFcally, we could have plotted the
'aline'
function in the following
alternate method:
x=-2:.01:7;
y=3*x-5;
plot(x,y)
To compare the two methods, we note that:
1.
plot
requires a user-supplied
x
-array (abscissa points) and a
constructed
y
-array (ordinate points), while
fplot
only requires
the name of the function Fle, deFned previously and stored in a
function
M-Fle
and the endpoints of the interval.
2. The
fplot
automatically creates a sampled domain that is used
to plot the function, taking into account the type of function being
plotted and using enough points to make the display appear con-
tinuous. On the other hand,
plot
requires that you choose the
array length yourself.