UNIT C_Rect;
INTERFACE
TYPE Func=Function(x:real):real;
FUNCTION Rectangles(a,b:Real; f:Func; n:word):Real;
FUNCTION RectanglesRunge(a,b:Real; f:Func; var n: word;eps:Real):Real;
IMPLEMENTATION
FUNCTION Rectangles(a,b:Real; f:Func; n:word):Real;
VAR
h,f1,sum,x,y:Real;
i:Integer;
BEGIN
h := (b-a) / n; sum := 0; x := a;
for i := 1 to n do
begin
y := x; x := x + h; f1 := f((x + y)/2); sum := sum + f1;
end;
Rectangles:= sum*h;
END;
FUNCTION RectanglesRunge(a,b:Real; f:Func; var n: word; eps:Real):Real;
VAR
I1, I2: real;
BEGIN
I1 := Rectangles(a,b,f,n); n := n+n; I2 := Rectangles(a,b,f,n);
while abs(I1-I2) > 2*eps do
begin
if n >= 16383 then break;
I1 := I2;
n := n+n;
I2 := Rectangles(a,b,f,n);
end;
RectanglesRunge := I2;
END; BEGIN END. |