clear
all
;close
all
;clc;
syms
x1x2t
;
f=4*(x1-5)^2+(x2-6)^2;
f_grad=[diff(f,x1);diff(f,x2)];
X0=[8;9];
n=10;
epsonal=0.01;
fx=inline(f);
fx_grad=inline(f_grad);
X=X0;
Xk=X0;
while
1
fx0=fx(X0(1),X0(2));
fx0_grad=fx_grad(X0(1),X0(2));
Hk=eye(2);
Pk=-fx0_grad;
k=0;
while
1
param=Xk+t*Pk;
fx1=fx(param(1),param(2));
[tk,y]=equation_extremum(fx1,t,-1,5,epsonal);
Xk=Xk+tk*Pk;
fx0_k=fx(Xk(1),Xk(2));
fx0_grad_k=fx_grad(Xk(1),Xk(2));
if
fx0_grad_k.'*fx0_grad_k<=epsonal
fx0_grad=fx0_grad_k;
break
;
end
if
k==n;
X=Xk;
fx0=fx0_k;
fx0_grad=fx0_grad_k;
break
;
end
Sk=Xk-X;
Yk=fx0_grad_k-fx0_grad;
Hk=Hk+Sk*Sk.'/(Sk.'*Yk)-Hk*Yk*Yk.'*Hk/(Yk.'*Hk*Yk);
Pk=-Hk*fx0_grad_k;
k=k+1;
end
if
fx0_grad.'*fx0_grad<=epsonal
display(Xk);
display(fx0_k);
break
;