Page 72 -
P. 72
1. To evaluate the function for a specified value x=x1, enter
aline(x1) to get the function value at this point; that is, y = 3x – 5.
1
1
2. To plot y = 3x – 5 for a range of x values, say [–2, 7], enter:
1
1
fplot('aline',[-2,7])
NOTE The above example illustrates a function with one input and one out-
put. The construction of a function M-file of a function having n inputs and m
outputs starts with:
function [y1,y2,...,ym]=funname(x1,x2,...,xn)
Above, using a function M-file, we showed a method to plot the defined
function aline on the interval (–2, 7) using the fplot command. An alter-
native method is, of course, to use arrays, in the manner specified in Chapter
1. Specifically, 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 file, defined previously and stored in a
function M-file 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.
Both methods, therefore, have their own advantages and it depends on the
particular problem whether to use plot or fplot.
We are now in position to explore the use of some of the most familiar func-
tions.
3.2 Examples with Affine Functions
The equation of an affine function is given by:
© 2001 by CRC Press LLC