type FunctionType function real real function real real begin end func

 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
type FunctionType = function(x: real): real;
function f(x: real): real; begin f := x end;
function IntegralSimpson(a, b: real; f: FunctionType; e: real): real;
var
h, x, s, s1, s2, s3, sign: real;
begin
if (a = b) then
begin
IntegralSimpson := 0; exit
end;
if (a > b) then
begin
x := a; a := b; b := x; sign := -1
end
else sign:=1;
h := b - a; s := f(a) + f(b); s2 := s;
repeat
s3 := s2; h := h/2; s1 := 0; x := a + h;
repeat
s1 := s1 + 2*f(x); x := x + 2*h;
until (not(x < b));
s := s + s1; s2 := (s + s1)*h/3; x := abs(s3 - s2)/15
until (not(x > e));
IntegralSimpson := s2*sign;
end;
begin
writeln(IntegralSimpson(0, 1, f, 0.001));
writeln; writeln('Press Enter'); readln;
end.