summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/metapost/bpolynomial/examples.mp
blob: 135b7881fdc0f082d4034e13220080c9d6b8af41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
input bpolynomial;
input graph
prologues := 3;


beginfig(1);
  newBPolynomial.f(2, 0, -3, -1);
  draw f.getPath(-2, 2) xscaled 1cm yscaled 0.1cm;
endfig;


beginfig(2);
  newBPolynomial.f(2, 0, -3, -1);
  for x=-2 step .25 until 2:
    label(btex $\star$ etex, (x, f.eval(x)) xscaled 1cm yscaled 0.1cm);
  endfor
endfig;


beginfig(3);
numeric u;
u := 0.5cm;
  %%% Draw a coordinate system.
  xmin := -5; xmax := 6;
  ymin := -5; ymax := 6;
  drawarrow ((xmin,0)--(xmax,0)) scaled u;
  drawarrow ((0,ymin)--(0,ymax)) scaled u;
  drawoptions(withpen pencircle scaled 1bp);
  %%% Define polynomial f of degree 2.
path f[];
  newBPolynomial.f(0, 0.5, -2, 0);
  f1 := f.getPath(-2, 0);
  f2 := f.getPath(0, 4);
  f3 := f.getPath(4, 5.5);
  draw f1 scaled u dashed evenly scaled 2;
  draw f3 scaled u dashed evenly scaled 2;
  draw f2 scaled u dashed withdots
    withpen pencircle scaled 1.5bp withcolor .5white;
  %%% Define polynomial g of degree 3.
path g;
  newBPolynomial.g(0.3, 0, -3, -1);
  g := g.getPath(-3.5, 4);
  show g;
  draw g scaled u;
  %%% Write table with some points of g to log file.
  show "Polynomial: " & decimal g.a & "x^3+" & decimal g.b
    & "x^2+" & decimal g.c & "x+" & decimal g.d;
  for x=-5 upto 5:
    show (x, g.eval(x));
  endfor
endfig;


beginfig(4);
path f,g;
  xmin := -7; xmax := 7;
  ymin := -7; ymax := 7;
  newBPolynomial.f(0, 0.5, -2, 0);
  f := f.getPath(xmin, xmax);
  newBPolynomial.g(0.3, 0, -3, -1);
  g := g.getPath(xmin, xmax);
  draw begingraph(10cm, 6cm);
    setrange(xmin,ymin, xmax,ymax);
    autogrid(grid.bot, grid.lft)
      dashed withdots withpen pencircle scaled .7bp withcolor .5white;
    drawoptions(withpen pencircle scaled 1bp);
    gdraw f dashed evenly scaled 2;
    gdraw g;
    drawoptions();
  endgraph;
endfig;

end