全文预览

优化方法作业第二版

上传者:叶子黄了 |  格式:doc  |  页数:19 |  大小:506KB

文档介绍
esidual is 2.381565Р--The 3-th iter, the residual is 3.448742Р…………………………Р--The 1516-th iter, the residual is 0.000368Р--The 1517-th iter, the residual is 0.000099Рxk =Р 1.0001Р 1.0002РMATLAB截屏:Р共轭梯度法Р源程序如下:Рfunction x_star =Conj (x0,eps) Рgk = grad(x0);Рres = norm(gk);Р k = 0; Р dk = -gk;Р while res > eps && k<=1000Р ak =1; f0 = fun(x0);f1 = fun(x0+ak*dk);slope = dot(gk,dk);Р while f1 > f0 + 0.1*ak*slope Р ak = ak/2; Р xk = x0 + ak*dk; Р f1 = fun(xk); Р end Р d0=dk;g0=gk;Р k=k+1;Р x0=xk;gk=grad(xk);f=(norm(gk)/norm(g0))^2;Р res=norm(gk);dk=-gk+f*d0;Рfprintf('--The %d-th iter, the residual is %f\n',k,res); Р end Р x_star = xk; Р end Рfunction f=fun(x)Рf=(1-x(1))^2+100*(x(2)-x(1)^2)^2;РendРfunction g=grad(x)Рg=zeros(2,1);Рg(1)=400*x(1)^3-400*x(1)*x(2)+2*x(1)-2;Рg(2)=-200*x(1)^2+200*x(2);Рend

收藏

分享

举报
下载此文档