implementation
//PROGRAM D3R9
//Driver for routine GAULEG
uses
unit2;
{$R *.DFM}
Function FUNC(X:real):real;
begin
FUNC:= X * Exp(-X);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
F:TextFile; I,NPOINT:Integer;
X1,X2,X3,XX:real;
X,W:array[0..10] of real;
const
s1='%14.6f'; s2='%10.6f'; s3='###';
begin
NPOINT:=10;
X1:=0;
X2:=1;
X3:=10;
GAULEG(X1,X2,X,W,NPOINT);
//输出计算结果到文件
AssignFile(F, 'd:\delphi_shu\p3\d3r9.dat');
Rewrite(F);
Writeln(F, ' # X(I) W(I)');
For I:= 1 To NPOINT do
Writeln(F,' ',FormatFloat(s3,I),Format(s1,[X[I]]),
Format(s1,[W[I]]));
//Demonstrate the use of GAULEG for an integral
GAULEG(X1,X3,X,W,NPOINT);
XX:=0;
For I:= 1 To NPOINT do
XX:= XX + W[I] * FUNC(X[I]);
Writeln(F);
Writeln(F,'Integral from GAULEG: ',Format(s2,[XX]));
Writeln(F,'Actual value: ',Format(s2,[1-(1+x3)*exp(-x3)]));
CloseFile(F);
//屏幕显示计算结果
memo1.Lines.LoadFromFile('d:\delphi_shu\p3\d3r9.dat');
end;