数学算法
源代码在线查看: d3r1.txt
implementation
//PROGRAM D3R1
//Driver for routine TRAPZD
uses
unit2;
{$R *.DFM}
Function FUNC(X:real):real;
begin
FUNC:= Sqr(X) * (Sqr(x) - 2) * Sin(X);
end;
Function FINT(X:real):real;
//Integral of FUNC
var
AAA:real;
begin
AAA:= 4 * X * (Sqr(x) - 7) * Sin(X);
FINT:= AAA - (Sqr(Sqr(x)) - 14 * Sqr(x) + 28) * Cos(X);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
F:TextFile; I:Integer;
A,B,S:real;
const
s1='%16.6f'; s2='###';s3='%9.6f';
NMAX = 14; PIO2=1.5707963;
begin
A:=0;
B:=PIO2;
//输出计算结果到文件
AssignFile(F, 'd:\delphi_shu\p3\d3r1.dat');
Rewrite(F);
Writeln(F, 'Integral of FUNC with 2^(n-1) points');
Writeln(F, 'Actual value of integral is: ',
format(s3,[(fint(b)-fint(a))]));
Writeln(F, ' n Approx. Integral');
For I:= 1 To NMAX do
begin
TRAPZD(A,B,S,I);
Writeln(F,' ',FormatFloat(s2,I),Format(s1,[s]));
end;
CloseFile(F);
//屏幕显示计算结果
memo1.Lines.LoadFromFile('d:\delphi_shu\p3\d3r1.dat');
end;