Graphics Programs Reference
In-Depth Information
It's not too hard to figure out why our regions aren't shaded; that's be-
cause we used plot (which plots curves) instead of patch (which plots filled
patches). So that suggests we should try changing the last line of the
M-file to
patch([xvals, xvals], [ffun(xvals), gfun(xvals)])
That gives the error message
??? Error using ==> patch
Not enough input arguments.
Error in ==> shadecurves.m
On line 9 ==> patch([xvals, xvals], [ffun(xvals),
gfun(xvals)])
So we go back and try
>> help patch
to see if we can get the syntax right. The help lines indicate that patch
requires a third argument, the color (in RGB coordinates) with which our
patchis to be filled. So we change our final line to, for instance,
patch([xvals,xvals], [ffun(xvals),gfun(xvals)], [.2,0,.8])
That gives us now as output to shadecurves(xˆ2, sqrt(x), 0, 1);
axis square the picture shown in Figure 11-6.
That's better, but still not quite right, because we can see a mysterious
diagonal line down the middle. Not only that, but if we try
>> syms x; shadecurves(xˆ2, xˆ4, -1.5, 1.5)
we now get the bizarre picture shown in Figure 11-7.
There aren't a lot of lines in the M-file, and lines 7 and 8 seem OK, so
the problem must be with the last line. We need to reread the online help for
patch .Itindicatesthat patch drawsafilled2Dpolygondefinedbythevectors
X and Y, which are its first two inputs. A way to see how this is working is to
change the “50” in line 9 of the M-file to something much smaller, say 5, and
then insert a breakpoint in the M-file before line 9. At this point, our M-file
in the Editor/Debugger window now looks like Figure 11-8. Note the large dot
to the left of the last line, indicating the breakpoint. When we run the M-file
with the same input, we now obtain in the Command Window a K>> prompt.
At this point, it is logical to try to list the coordinates of the points that are
the vertices of our filled polygon, so we try
Search WWH ::




Custom Search