优化方法作业第二版.

上传人:jiups****uk12 文档编号:90755355 上传时间:2019-06-16 格式:DOC 页数:19 大小:506.01KB
返回 下载 相关 举报
优化方法作业第二版._第1页
第1页 / 共19页
优化方法作业第二版._第2页
第2页 / 共19页
优化方法作业第二版._第3页
第3页 / 共19页
优化方法作业第二版._第4页
第4页 / 共19页
优化方法作业第二版._第5页
第5页 / 共19页
点击查看更多>>
资源描述

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

1、优化方法上机大作业 院 系:化工与环境生命学部姓 名:李翔宇学 号:31607007指导教师:肖现涛第一题: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, the r

2、esidual 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.372079-The 2-th iter,

3、 the residual is 12.079876-The 3-th iter, the residual is 11.054105-The 9144-th iter, the residual is 0.000105-The 9145-th iter, the residual is 0.000102-The 9146-th iter, the residual is 0.000100xk = 0.99990.9998MATLAB截屏:2. 牛顿法源程序如下:function x_star = NEWTON(x0,eps) gk = grad(x0); bk = grad2(x0)(-1)

4、; res = norm(gk); k = 0; while res eps & k x0=0,0;eps=1e-4; xk=NEWTON(x0,eps)-The 1-th iter, the residual is 447.213595-The 2-th iter, the residual is 0.000000xk = 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

5、 & k f0 + 0.1*ak*slope ak = ak/2; xk = x0 + 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; endf

6、unction 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=Bfgs(x0,eps)-The 1-th iter, the residual is 3.271712-The 2-th iter, the residual is 2.381565-The 3-th iter, the resid

7、ual is 3.448742-The 1516-th iter, the residual is 0.000368-The 1517-th iter, the residual is 0.000099xk = 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); en

8、d 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 %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*

9、x(2);end 运行结果: x0=0,0; eps=1e-4; xk=Conj(x0,eps)-The 1-th iter, the residual is 3.271712-The 2-th iter, the residual is 1.380542-The 3-th iter, the residual is 4.527780-The 4-th iter, the residual is 0.850596-The 73-th iter, the residual is 0.001532-The 74-th iter, the residual is 0.000402-The 75-th

10、 iter, the residual is 0.000134-The 76-th iter, the residual is 0.000057xk = 0.9999 0.9999MATLAB截屏:第二题:解 :目标函数文件 f1.mfunction 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 =

11、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.898717426488211.00128197198571算法编程利用程序调用格式第三题:1.解:将目标函数

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 其它中学文档

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