
Scripts and Functions
Q = quadl(@humps,0,1)
computes the area under the curve in the graph and produces
Q=
29.8583
Finally, the graph shows that the function is never zero on this interval. So,
ifyousearchforazerowith
z = fzero(@humps,.5)
you will find one outside the interval
z=
-0.1316
Vectorization
One way to make your M ATLAB programs run faster is to vectorize the
algorithms you use in constructing the programs. Where other programming
languages might use
for loops or DO loops, MATLAB can use vector or matrix
operations. A simple example involves creating a table of logarithms:
x = .01;
for k = 1:1001
y(k) = log10(x);
x=x+.01;
end
A vectorized version of the same code is
x = .01:.01:10;
y = log10(x);
For more co mplicated code, vectorization options are not always so obv io us.
For More Information See “Improving Performan ce and Memo r y U sa ge”
in the MATLAB Programming documentation for other techniques that you
can use.
4-31
Commenti su questo manuale