implementation
//PROGRAM D9R4
//Driver for routine DRENT
uses
unit2;
{$R *.DFM}
Function FUNC(X:real):real;
begin
FUNC:= BESSJ0(X);
end;
Function DERIV(X:real):real;
begin
DERIV:= -BESSJ1(X);
end;
procedure TForm1.Button1Click(Sender: TObject);
const
s1='%12.6f'; s2 = '#0'; TOL = 0.000001; EQL = 0.0001;
var
F:TextFile;
AMIN:array[0..20] of real;
I,J,NMIN,IFLAG:integer; AX,BX,CX,FA,FB,FC,DBR,XMIN:real;
begin
//输出计算结果到文件
AssignFile(F, 'd:\delphi_shu\p9\d9r4.dat');
Rewrite(F);
Writeln(F, 'Minima of the function BESSJ0');
NMIN:= 0;
Writeln(F, ' Min. # X BESSJ0(X) BESSJ1(X) DBRENT');
For I:=1 To 100 do
begin
AX:= I;
BX:=I + 1;
MNBRAK(AX, BX, CX, FA, FB, FC);
DBR:= DBRENT(AX, BX, CX, TOL, XMIN);
If NMIN = 0 Then
begin
AMIN[1]:= XMIN;
NMIN:= 1;
Writeln(F,' ',FormatFloat(s2,NMIN),Format(S1,[XMIN]),
Format(S1,[BESSJ0(XMIN)]),Format(S1,[BESSJ1(XMIN)]),Format(S1,[DBR]));
end
Else
begin
IFLAG:= 0;
For J:= 1 To NMIN do
If Abs(XMIN - AMIN[J]) If IFLAG = 0 Then
begin
NMIN:= NMIN + 1;
AMIN[NMIN]:= XMIN;
Writeln(F,' ',FormatFloat(s2,NMIN),Format(S1,[XMIN]),
Format(S1,[BESSJ0(XMIN)]),Format(S1,[BESSJ1(XMIN)]),Format(S1,[DBR]));
end;
end;
end;
CloseFile(F);
//屏幕显示计算结果
memo1.Lines.LoadFromFile('d:\delphi_shu\p9\d9r4.dat');
end;