优化方法作业第二版

上传人:des****85 文档编号:255699554 上传时间:2022-02-17 格式:DOC 页数:19 大小:480KB
返回 下载 相关 举报
优化方法作业第二版_第1页
第1页 / 共19页
优化方法作业第二版_第2页
第2页 / 共19页
优化方法作业第二版_第3页
第3页 / 共19页
优化方法作业第二版_第4页
第4页 / 共19页
优化方法作业第二版_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《优化方法作业第二版》由会员分享,可在线阅读,更多相关《优化方法作业第二版(19页珍藏版)》请在金锄头文库上搜索。

1、精选优质文档-倾情为你奉上优化方法上机大作业 院 系:化工与环境生命学部姓 名:李翔宇学 号:指导教师:肖现涛第一题:1. 最速下降法源程序如下:function x_star = ZSXJ(x0,eps) gk = grad(x0); res = norm(gk); k = 0; while res eps & k f0 + 0.0001*ak*slope ak = ak/2; xk = x0 + ak*dk; f1 = fun(xk); end k = k+1; x0 = xk; gk = grad(xk);res = norm(gk); fprintf(-The %d-th iter,

2、the residual is %fn,k,res); end x_star = xk; end function f = fun(x) f = (1-x(1)2 + 100*(x(2)-x(1)2)2; endfunction g = grad(x) g = zeros(2,1); g(1)=2*(x(1)-1)+400*x(1)*(x(1)2-x(2); g(2) = 200*(x(2)-x(1)2); end 运行结果: x0=0,0; esp=1e-4; xk=ZSXJ(x0,eps)-The 1-th iter, the residual is 13.-The 2-th iter,

3、the residual is 12.-The 3-th iter, the residual is 11.-The 9144-th iter, the residual is 0.-The 9145-th iter, the residual is 0.-The 9146-th iter, the residual is 0.xk = 0.99990.9998MATLAB截屏:2. 牛顿法源程序如下:function x_star = NEWTON(x0,eps) gk = grad(x0); bk = grad2(x0)(-1); res = norm(gk); k = 0; while

4、res eps & k x0=0,0;eps=1e-4; xk=NEWTON(x0,eps)-The 1-th iter, the residual is 447.-The 2-th iter, the residual is 0.xk = 1.00001.0000MATALB截屏;3. BFGS方法源程序如下:function x_star = Bfgs(x0,eps) g0 = grad(x0); gk=g0; res = norm(gk); Hk=eye(2); k = 0; while res eps & k f0 + 0.1*ak*slope ak = ak/2; xk = x0 +

5、 ak*dk; f1 = fun(xk); end k = k+1; fa0=xk-x0; x0 = xk; g0=gk;gk = grad(xk);y0=gk-g0;Hk=(eye(2)-fa0*(y0)/(fa0)*(y0)*(eye(2)-(y0)*(fa0)/(fa0)*(y0)+(fa0*(fa0)/(fa0)*(y0);res = norm(gk); fprintf(-The %d-th iter, the residual is %fn,k,res); end x_star = xk; endfunction f=fun(x) f=(1-x(1)2 + 100*(x(2)-x(1

6、)2)2; endfunction g = grad(x) g = zeros(2,1); g(1)=2*(x(1)-1)+400*x(1)*(x(1)2-x(2); g(2) = 200*(x(2)-x(1)2); end 运行结果: x0=0,0; esp=1e-4; xk=Bfgs(x0,eps)-The 1-th iter, the residual is 3.-The 2-th iter, the residual is 2.-The 3-th iter, the residual is 3.-The 1516-th iter, the residual is 0.-The 1517

7、-th iter, the residual is 0.xk = 1.0001 1.0002MATLAB截屏:4. 共轭梯度法源程序如下:function x_star =Conj (x0,eps) gk = grad(x0);res = norm(gk); k = 0; dk = -gk; while res eps & k 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(g

8、k);dk=-gk+f*d0;fprintf(-The %d-th iter, the residual is %fn,k,res); end x_star = xk; end function f=fun(x)f=(1-x(1)2+100*(x(2)-x(1)2)2;endfunction 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 运行结果: x0=0,0; eps=1e-4; xk=Conj(x0,eps)-The 1-th iter, the resid

9、ual is 3.-The 2-th iter, the residual is 1.-The 3-th iter, the residual is 4.-The 4-th iter, the residual is 0.-The 73-th iter, the residual is 0.-The 74-th iter, the residual is 0.-The 75-th iter, the residual is 0.-The 76-th iter, the residual is 0.xk = 0.9999 0.9999MATLAB截屏:第二题:解 :目标函数文件 f1.mfunc

10、tion f=f1(x)f=4*x(1)-x(2)2-12;等式约束函数文件 h1.mfunction he=h1(x)he=25-x(1)2-x(2)2;不等式约束函数文件 g1.mfunction gi=g1(x)gi=10*x(1)-x(1)2+10*x(2)-x(2)2-34;目标函数的梯度文件 df1.mfunction g=df1(x)g = 4, 2.0*x(2);等式约束(向量)函数的Jacobi矩阵(转置)文件dh1.mfunction dhe=dh1(x)dhe = -2*x(1), -2*x(2);不等式约束(向量)函数的Jacobi矩阵(转置)文件dg1.mfunction dgi=dg1(x)dgi = 10-2*x(1), 10-2*x(2);然后在 Matlab 命令窗口输入如下命令:x0=0,0;x,mu,lambda,output=multphr(f1,h1,g1,df1,dh1,dg1,x0);得到如下输出:x =4.8211.571算法编程利用程序调用格式第三题:1.解:将目标函数改写为向量形式:x*a*x-b*x程序代码:n=2;a=0.5,0;0,1;b=2 4;c=1 1;cvx_beginvariable x(n)minimize( x*a*x-b*x)subject toc * x

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号