implementation
//PROGRAM D2R2
//Driver for routine RATINT
uses
unit2;
{$R *.DFM}
Function FUNC(x:real):real;
begin
FUNC:= X * Exp(-X)/(Sqr(X - 1)+1);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
X,Y:array[0..6] of real;
XX,YY,DYY,YEXP:real;
F:TextFile; I:Integer;
const
NPT=6; s1='%12.6f'; s2='0.0000E+00'; s3='%6.2f';
begin
For I:=1 to NPT do
begin
X[I]:= I * 2 / NPT;
Y[I]:= FUNC(X[I]);
end;
//输出计算结果到文件
AssignFile(F, 'd:\delphi_shu\p2\d2r2.dat');
Rewrite(F);
Writeln(F, 'Diagonal rationnal function interpolation');
Writeln(F,' X interap. accuracy actual');
For I:=1 To 10 do
begin
XX:= 0.2 * I;
RATINT(X, Y, NPT, XX, YY, DYY);
YEXP:= FUNC(XX);
Writeln(F,Format(s3,[XX]),Format(s1,[YY]),' ',
FormatFloat(s2,DYY),Format(s1,[YEXP]));
end;
CloseFile(F);
//屏幕显示计算结果
memo1.ScrollBars:=ssVertical;
memo1.Lines.LoadFromFile('d:\delphi_shu\p2\d2r2.dat');
end;