implementation
//PROGRAM D9R6
//Driver for routine POWELL
uses
unit2;
{$R *.DFM}
Function FUNC(X:real):real;
begin
FUNC:=F1DIM(X);
end;
Function FUNC2(X:array of real;N:integer):real;
begin
Func2:=0.5- BESSJ0(Sqr(X[1]-1)+Sqr(X[2]-2)+Sqr(X[3]-3));
end;
procedure TForm1.Button1Click(Sender: TObject);
const
s1='%12.6f'; s2 = '#0'; NP = 3; NDIM = 3; FTOL = 0.000001;
var
F:TextFile;
P:array[0..3] of real; XI:matrx2;
I,J,ITER:integer; FRET:real;
begin
SetLength(XI,4,4);
P[1]:=1.5; P[2]:=1.5; P[3]:=2.5;
For I:=1 To NP do
begin
For J:=1 To NP do
XI[I,J]:= 0;
end;
XI[1,1]:=1; XI[2,2]:=1; XI[3,3]:=1;
//输出计算结果到文件
AssignFile(F, 'd:\delphi_shu\p9\d9r6.dat');
Rewrite(F);
POWELL(P, XI, NDIM, NP, FTOL, ITER, FRET);
Writeln(F);
Writeln(F, ' Iterations: ', FormatFloat(s2,ITER));
Writeln(F);
Writeln(F, ' Minimum found at');
Writeln(F);
Writeln(F, ' ',Format(s1,[P[1]]),Format(s1,[P[2]]),Format(s1,[P[3]]));
Writeln(F);
Writeln(F, ' Minimum function value = ',Format('%8.6f',[FRET]));
Writeln(F);
Writeln(F, ' Minimum function value is at 1.0 2.0 3.0 ');
CloseFile(F);
//屏幕显示计算结果
memo1.Lines.LoadFromFile('d:\delphi_shu\p9\d9r6.dat');
end;