Function GOLDEN(AX, BX, CX, TOL:real;var XMIN:real):real;
const
R = 0.61803399; C = 0.38196601;
Var
X0,X3,X1,X2,F0,F1,F2,F3:real;
begin
X0:=AX;
X3:=CX;
If Abs(CX - BX) > Abs(BX - AX) Then
Begin
X1:=BX;
X2:=BX + C * (CX - BX);
end
Else
begin
X2:=BX;
X1:=BX - C * (BX - AX);
end;
F1:=FUNC(X1);
F2:=FUNC(X2);
While Abs(X3 - X0) > TOL * (Abs(X1) + Abs(X2)) do
begin
If F2 < F1 Then
begin
X0:=X1;
X1:=X2;
X2:=R * X1 + C * X3;
F0:=F1;
F1:=F2;
F2:=FUNC(X2);
end
Else
begin
X3:=X2;
X2:=X1;
X1:=R * X2 + C * X0;
F3:=F2;
F2:=F1;
F1:=FUNC(X1);
end;
end;
If F1 < F2 Then
begin
GOLDEN:=F1;
XMIN:=X1;
end
Else
begin
GOLDEN:=F2;
XMIN:=X2;
end;
end;