unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,unit1, Dialogs;
procedure TRAPZD(A, B:real;var S:real; N:integer);
procedure QSIMP(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 QSIMP(A, B:real; var S:real);
const
EPS = 0.000001; JMAX = 20;
var
J:integer; OST,OS,ST:real;
begin
OST:=-1E+30;
OS:=-1E+30;
For J:=1 To JMAX do
begin
TRAPZD(A, B, ST, J);
S:=(4 * ST - OST) / 3;
If Abs(S - OS) < EPS * Abs(OS) Then Exit;
OS:=S;
OST:=ST;
end;
ShowMessage('Too many steps.');
end;
end.