最优化牛顿法求极值的问题!求助!
:L最优化牛顿法求极值的问题!g为f的梯度,h为hessian阵,原理即为x(k+1)=x(k)-h^(-1)*g用其迭代!我迭代一次的结果是对的,但再往下就不对了,迭代不出结果!还有迭代的终止条件应选什么?麻烦帮我看一看!
clear
f='100*(x2-x1^2)^2+(1-x1)^2';
x0=[-1.2 ;1];
n=2;
k=0;
ee=1e-6;
xx=sym(x0);
for i=1:1:n
xx(i)=sprintf('x%d',i);
df(i)=diff(f,xx(i));
end
h=;
g=;
%while(1)
for j=1:10
k=k+1;
for i=1:1:n
h=subs(h,xx(i),x0(i));
end
for i=1:1:n
g=subs(g,xx(i),x0(i));
end
x1=x0-inv(h)*g;
for i=1:2
f=subs(f,xx(i),x1(i));
end
if norm(f)<ee
break
end
x0(1)=x1(1);
x0(2)=x1(2);
disp();
end
页:
[1]