beginfig(13);
path f, g, A;
xmin := -3; xmax := 6;
ymin := -3; ymax := 6;
newBPolynomial.f(-0.25, 0.5, 2, -1);
newBPolynomial.g(0, 0.5, -2, 0);
f := f.getPath(-2.5, 5.5);
g := g.getPath(-1.5, 5.5);
%%% Find area between f and g.
A := buildcycle(g, reverse f);
draw begingraph(10cm, 6cm);
setrange(xmin,ymin, xmax,ymax);
autogrid(grid.bot, grid.lft) dashed evenly withcolor .9white;
%%% Fill area with transparent colour.
gfill A withcolor transparent (1, .3, (1, 0.5, 0));
drawoptions(withpen pencircle scaled 1bp);
gdraw f;
gdraw g dashed evenly scaled 2;
drawoptions();
endgraph;
endfig;
beginfig(14);
path f, g, A;
T := identity xscaled 10mm yscaled 6mm;
%%% Draw coordinate system.
xmin := -3; xmax := 6;
ymin := -3; ymax := 6;
drawoptions(withpen pencircle scaled 1bp withcolor 0.8white);
drawarrow ((xmin,0)--(xmax,0)) transformed T;
drawarrow ((0,ymin)--(0,ymax)) transformed T;
newBPolynomial.f(-0.25, 0.5, 2, -1);
newBPolynomial.g(0, 0.5, -2, 0);
f := f.getPath(-2.5, 4.2);
g := g.getPath(-1, 5);
A := buildcycle(g, reverse f);
%%% Fill area with pattern.
drawoptions();
hatchoptions(withcolor (0.6, 0.3, 0.3));
hatchfill A transformed T
withcolor (-45, 2mm, -0.5bp) withcolor (45, 2mm, -0.5bp);
drawoptions(withpen pencircle scaled 1bp);
draw f transformed T;
draw g transformed T dashed evenly scaled 2;
endfig;
%%% The following figures work around a bug in metafun's
%%% mp-form.mp package for the original figures 11 to 13.
%%% The bug shows up when rendering negative numbers
%%% on corrdinate axes using macro 'format'.
beginfig(21);
path f, g;
xmin := -7; xmax := 7;
ymin := -7; ymax := 7;
%%% Define polynomials f and g.
newBPolynomial.f(0.3, 0, -3, -1);
f := f.getPath(xmin, xmax);
newBPolynomial.g(0, 0.5, -2, 0);
g := g.getPath(xmin, xmax);
%%% Draw graph.
draw begingraph(10cm, 6cm);
setrange(xmin,ymin, xmax,ymax);
% autogrid(grid.bot, grid.lft) dashed evenly withcolor .9white;
for i=xmin+1 step 2 until xmax-1:
grid.bot(decimal i, i) dashed evenly withcolor .9white;
endfor
for i=ymin+1 step 2 until ymax-1:
grid.lft(decimal i, i) dashed evenly withcolor .9white;
endfor
drawoptions(withpen pencircle scaled 1bp);
gdraw f;
gdraw g dashed evenly scaled 2;
drawoptions();
endgraph;
show f;
%%% Write table with some points of f to log file.
show "Polynomial: " & decimal f.a & "x^3 + " &
decimal f.b & "x^2 + " & decimal f.c & "x + " & decimal f.d;
for x=-5 upto 5:
show (x, f.eval(x));
endfor
endfig;