Function RTFLSP(X1, X2, XACC:real):real;
Label 99;
var
XL,XH,SWAP,FL,FH,RTF,DX,F,DEL:real; J,MAXIT:integer;
begin
MAXIT:=30;
FL:=FUN(X1);
FH:=FUN(X2);
If FL * FH > 0 Then
ShowMessage('Root must be bracketed for false position');
If FL < 0 Then
begin
XL:=X1;
XH:=X2;
end
Else
begin
XL:=X2;
XH:=X1;
SWAP:=FL;
FL:=FH;
FH:=SWAP;
end;
DX:=XH - XL;
For J:=1 To MAXIT do
begin
RTF:=XL + DX * FL / (FL - FH);
F:=FUN(RTF);
If F < 0 Then
begin
DEL:=XL - RTF;
XL:=RTF;
FL:=F;
end
Else
begin
DEL:=XH - RTF;
XH:=RTF;
FH:=F;
end;
DX:=XH - XL;
If (Abs(DEL) < XACC) Or (F = 0) Then goto 99;
end;
ShowMessage('RTFLSP exceed maximum iterations');
99: RTFLSP:=RTF;
end;