unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,unit1, Dialogs;
procedure TRAPZD(A, B:real;var S:real; N:integer);
procedure QTRAP(A, B:real; var S:real);
implementation
procedure TRAPZD(A, B:real;var S:real; N:integer);
var
J,IT:integer;
TNM,DEL,X,SUM:real;
begin
If N = 1 Then
begin
S:=0.5 * (B - A) * (FUNC(A) + FUNC(B));
IT:=1;
end
Else
begin
IT:=Trunc(exp((N - 2)*Ln(2)));
TNM:=IT;
DEL:=(B - A) / TNM;
X:=A + 0.5 * DEL;
Sum:=0;
For J:=1 To IT do
begin
Sum:=Sum + FUNC(X);
X:=X + DEL;
end;
S:=0.5 * (S + (B - A) * Sum / TNM);
end;
end;
procedure QTRAP(A, B:real; var S:real);
const
EPS = 0.000001; JMAX = 20;
var
OLDS:real; J:integer;
begin
OLDS:= -1E+30;
For J:= 1 To JMAX do
begin
TRAPZD(A, B, S, J);
If (Abs(S - OLDS) < (EPS * Abs(OLDS))) Then Exit;
OLDS:= S;
end;
ShowMessage('Too many steps.');
end;
end.