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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
input bpolynomial;
input graph
prologues := 3;
transform T;
T = identity xscaled 10mm yscaled 1mm;
beginfig(1);
newBPolynomial.f(2, 0, -3, -1);
draw f.getPath(-2, 2) transformed T;
endfig;
beginfig(2);
newBPolynomial.f(2, 0, -3, -1);
draw f.getPath(-2, 2) transformed T;
x := 1.5;
show (x, f.eval(x));
dotlabeldiam := 2bp;
dotlabel.ulft(btex $(1.5, 1.25)$ etex, (x, f.eval(x)) transformed T);
endfig;
beginfig(3);
newBPolynomial.f(2, 0, -3, -1);
draw f.getPath(-2, 2) transformed T;
draw f.getTangent(-1, -1, 1) transformed T;
endfig;
beginfig(4);
newBPolynomial.f(2, 0, -3, -1);
draw f'.getPath(-2, 2) transformed T;
draw f'.getTangent(1, -1, 1) transformed T;
endfig;
beginfig(5);
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(6);
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 evenly withcolor .9white;
drawoptions(withpen pencircle scaled 1bp);
gdraw f dashed evenly scaled 2;
gdraw g;
drawoptions();
endgraph;
endfig;
beginfig(7);
xmin := -6; xmax := 6;
ymin := -6; ymax := 6;
newBPolynomial.f(0.3, -0.5, -0.5, -1);
draw begingraph(10cm, 6cm);
setrange(xmin,ymin, xmax,ymax);
autogrid(grid.bot, grid.lft) dashed evenly withcolor .9white;
drawoptions(withpen pencircle scaled 1bp);
%%% Draw f and its derivatives f', f'', f'''.
gdraw f.getPath(xmin, xmax);
gdraw f'.getPath(xmin, xmax) dashed evenly scaled 2;
gdraw f''.getPath(xmin, xmax) dashed withdots
withpen pencircle scaled 2bp;
gdraw f'''.getPath(-5, 5) withcolor .6white;
%%% Draw tangents and mark points.
x := 2;
drawoptions(withcolor red+.6(green+blue));
gdraw f.getTangent(x, -2, 2);
gdraw f'.getTangent(x, -1, 1);
gdraw f''.getTangent(x, -2, 2);
gdraw f'''.getTangent(x, -2, 2);
drawoptions(withcolor blue+.6(red+green));
dotlabeldiam := 2.5bp;
gdotlabel("", (x, f.eval(x)));
gdotlabel("", (x, f'.eval(x)));
gdotlabel("", (x, f''.eval(x)));
gdotlabel("", (x, f'''.eval(x)));
drawoptions();
endgraph;
endfig;
end
|