优化方法作业第二版(共19页).doc
《优化方法作业第二版(共19页).doc》由会员分享,可在线阅读,更多相关《优化方法作业第二版(共19页).doc(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.mfuncti
11、on 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 =0cvx_end运算结果:Calling SDPT
12、3 4.0: 7 variables, 3 equality constraints For improved efficiency, SDPT3 is solving the dual problem.- num. of constraints = 3 dim. of socp var = 4, num. of socp blk = 1 dim. of linear var = 3* SDPT3: Infeasible path-following algorithms* version predcorr gam expon scale_data NT 1 0.000 1 0 it pste
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 优化 方法 作业 第二 19
限制150内