Download Learning METAPOST by Doing

Transcript
Learning MetaPost by doing
VOORJAAR 2005
beginfig(1);
repere(10cm,10cm,5cm,5cm,2cm,2cm);
trace.axes(0.5pt);
marque.unites(1mm);
y
%% Champs de directions
vardef F(expr x,y) = 1+y**2 enddef;
champ.segments(0,0,0.2,0.1,0.5white);
+1
x
+1
%% Courbes intégrales
for n = 0 upto 16:
a := (n/2) - 4;
draw ftrace(-1.5-a,1.5-a,50) en_place
withcolor (0.5,0.6,0.1);
endfor;
decoupe.repere;
etiquette.axes;
etiquette.unites;
label(btex $y’=1+yˆ2$ etex scaled 2.5,rpoint(0,-3));
endfig;
end;
y0 = 1 + y2
Riemann Sums
Another example of the courbes.mp macro package is the following illustration of
Riemann sums. We show two pictures for different number of segments.
y
verbatimtex
%&latex
\documentclass{article}
\everymath{\displaystyle}
\begin{document}
etex
Riemann Sum
y = f (x)
f (ξi )
input courbes;
vardef fx(expr t) = t enddef;
vardef fy(expr t) = (t-5)*sin(t)-cos(t)+2 enddef;
a
x0
xi−1
xi
b
xn
x
ξi
S=
n
X
i=1
numeric a,b,n,h;
a = 1; b = 7; n = 6; h = (b-a)/n;
color aubergine; aubergine = (37/256,2/256,29/256);
repere(10cm,10cm,2cm,3cm,1cm,1cm);
fill ((a,0)--ftrace(a,b,200)--(b,0)--cycle) en_place
withcolor 0.7red;
f (ξi )(xi − xi−1 )
y
for i=1 upto n:
path cc;
aa := a + (i-1) * h;
bb := aa + h;
ff := fy(aa + h/2);
cc := rpoint(aa,0)--rpoint(aa,ff)--rpoint(bb,ff)-rpoint(bb,0);
fill cc--cycle withcolor 0.8white;
draw cc;
endfor;
Riemann Sum
f (ξi )
y = f (x)
a
x0
xi−1xi
ξi
S=
n
X
i=1
b
xn
f (ξi )(xi − xi−1 )
beginfig(1);
x
trace.axes(0.5pt);
trace.courbe(a,b,200,2pt,aubergine);
decoupe.repere;
etiquette.axes;
51