Graphics Programs Reference
In-Depth Information
6
5
4
3
2
1
0
-1. 5
-1
-0. 5
0
0.5
1
1.5
Figure11-9
x
coordinates at which we evaluate the second function
g
. So letting
slavx
denote
xvals
reversed, we correct our M-file to read
function shadecurves(f, g, a, b)
%SHADECURVES Draws the region between two curves
% SHADECURVES(f, g, a, b) takes strings or expressions f
% and g, interprets them as functions, plots them between
%x=aandx=b,andshades the region in between.
% Example: shadecurves('sin(x)', '-sin(x)', 0, pi)
ffun = inline(vectorize(f)); gfun = inline(vectorize(g));
xvals = a:(b - a)/50:b; slavx = b:(a - b)/50:a;
patch([xvals,slavx], [ffun(xvals),gfun(slavx)], [.2,0,.8])
Nowitworksproperly.SampleoutputfromthisM-fileisshowninFigure 11-4.
Try it out on the other examples we have discussed, or on others of your choice.
Search WWH ::
Custom Search