carll;loseall;Ic;
symsx1x2t,
f=4*(x1-5)^2+(x2-6)^2;
f_ fard-(f(,f(:();
X0=[8;9];
n=10;
epsonal=0.01;
fxinline(f);
fx_ grad=inline(f. grad);
X=X0;
Xk=X0;
while 1
fx0-fx(X(1),X0(2));
fx0_ grad=fx_ grad()X0(2));
Hk=eye(2);
Pk=-fx0_ grad;
k=0;
while 1
param=Xk+t*Pk;
fx1=fx(param()param(2));
[tk,y]=equation_ extremum(x1+,-1,5,epsonal);
Xk=Xk+k*Pk;
fxO_ k-(X(),X();
fxO_ grad_ k=fx_ gal(l1(),)1(1);
iffx0_ grad_ k.*fx0_ grad_ k<=epsonal
fx0_ gerad=fx0_ grad_ k;
break;
end
if K==n;
X=Xk;
fxO=fx0_ k;
fx0_ grad=fx0_ grad. k;
break;
end
Sk=XkX;
Yk=fxO_ grad_ k-fx0_ grad;
Hk=Hk+Sk*Sk./(Sk.*Yk)-Hk*Yk*Yk.*HKk/(Yk.*Hk*Yk);
Pk=-Hk*fx0_ grad. k;
K=k+1; .
end
if fxO_ grad.!*fx0_ grad<=epsonal
display(Xk);
display(fx0_ k);
break;
end
end
运行结果:
Xk=
5.0000
6.0000
fx0_ k=
3.2815e-10