Метод Пауэлла
Таблица итераций
(точность eps=10e-3)
Номер итерации | |
|
1 | (3.244,0.748) | -4.185 |
2 | (2.236,-0.000) | -6.000 |
Пример приведен для квадратичной функции
procedure TFrmMain.Pawell(eps:double;fp:TWorldPoint);
const n=2;
var cappa:Double;
p_i:array [1..n] of TWorldPoint;
z,p,curx,lastx,lastxx,wavex:TWorldPoint;
k,l,i:integer;
screen:TScreenPoint;
begin
p_i[1].x:=1;p_i[1].y:=0;
p_i[2].x:=0;p_i[2].y:=1;
curx:=fp;
lastx:=fp;
wavex:=fp;
lastxx:=fp;
k:=1;
while true do
begin
for i:=1 to n do
begin
for l:=1 to n do
begin
xk:=wavex;
uk:=p_i[l];
cappa:=MakeDichotomy(-1000,1000,1e-5,eps/100,Pseudo1D);
if abs(cappa)<1e-8 then cappa:=0;
wavex.x:=wavex.x+cappa*p_i[l].x;
wavex.y:=wavex.y+cappa*p_i[l].y;
World2Screen(Area,CopyScr.Canvas.ClipRect,wavex,Screen);
Copyscr.Canvas.LineTo(Screen.x,Screen.y);
end;
p.x:=wavex.x-lastx.x;
p.y:=wavex.y-lastx.y;
xk:=wavex;
uk:=p;
cappa:=MakeDichotomy(-10000,10000,1e-5,eps/100,Pseudo1D);
if abs(cappa)<1e-8 then cappa:=0;
z.x:=wavex.x+cappa*p.x;
z.y:=wavex.y+cappa*p.y;
World2Screen(Area,CopyScr.Canvas.ClipRect,z,Screen);
Copyscr.Canvas.LineTo(Screen.x,Screen.y);
SetPoint(z);
for l:=1 to n-1 do
begin
p_i[l]:=p_i[l+1];
end;
p_i[n]:=p;
if i<>n then begin wavex:=z;lastx:=z; end;
end;{for i}
BuiltReport(wavex,p,k,cappa);
lastxx:=curx;
curx:=z;
if sqrt(sqr(curx.x-lastxx.x)+sqr(curx.y-lastxx.y))<eps then
break;
wavex:=curx;
lastx:=curx;
inc(k);
end;
end;