




已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
优化方法上机大作业 院 系:化工与环境生命学部姓 名:李翔宇学 号: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 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.372079-The 2-th iter, 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); 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 & 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; endfunction 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 residual 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); 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 %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 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 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 = 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.解:将目标函数改写为向量形式: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 SDPT3 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 pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime- 0|0.000|0.000|8.0e-001|6.5e+000|3.1e+002| 1.000000e+001 0.000000e+000| 0:0:00| chol 1 1 1|1.000|0.987|4.3e-007|1.5e-001|1.6e+001| 9.043148e+000 -2.714056e-001| 0:0:01| chol 1 1 2|1.000|1.000|2.6e-007|7.6e-003|1.4e+000| 1.234938e+000 -5.011630e-002| 0:0:01| chol 1 1 3|1.000|1.000|2.4e-007|7.6e-004|3.0e-001| 4.166959e-001 1.181563e-001| 0:0:01| chol 1 1 4|0.892|0.877|6.4e-008|1.6e-004|5.2e-002| 2.773022e-001 2.265122e-001| 0:0:01| chol 1 1 5|1.000|1.000|1.0e-008|7.6e-006|1.5e-002| 2.579468e-001 2.427203e-001| 0:0:01| chol 1 1 6|0.905|0.904|3.1e-009|1.4e-006|2.3e-003| 2.511936e-001 2.488619e-001| 0:0:01| chol 1 1 7|1.000|1.000|6.1e-009|7.7e-008|6.6e-004| 2.503336e-001 2.496718e-001| 0:0:01| chol 1 1 8|0.903|0.903|1.8e-009|1.5e-008|1.0e-004| 2.500507e-001 2.499497e-001| 0:0:01| chol 1 1 9|1.000|1.000|4.9e-010|3.5e-010|2.9e-005| 2.500143e-001 2.499857e-001| 0:0:01| chol 1 1 10|0.904|0.904|5.7e-011|1.3e-010|4.4e-006| 2.500022e-001 2.499978e-001| 0:0:01| chol 2 2 11|1.000|1.000|5.2e-013|1.1e-011|1.2e-006| 2.500006e-001 2.499994e-001| 0:0:01| chol 2 2 12|1.000|1.000|5.9e-013|1.0e-012|1.8e-007| 2.500001e-001 2.499999e-001| 0:0:01| chol 2 2 13|1.000|1.000|1.7e-012|1.0e-012|4.2e-008| 2.500000e-001 2.500000e-001| 0:0:01| chol 2 2 14|1.000|1.000|2.3e-012|1.0e-012|7.3e-009| 2.500000e-001 2.500000e-001| 0:0:01| stop: max(relative gap, infeasibilities) 1.49e-008- number of iterations = 14 primal objective value = 2.50000004e-001 dual objective value = 2.49999996e-001 gap := trace(XZ) = 7.29e-009 relative gap = 4.86e-009 actual relative gap = 4.86e-009 rel. primal infeas (scaled problem) = 2.33e-012 rel. dual = 1.00e-012 rel. primal infeas (unscaled problem) = 0.00e+000 rel. dual = 0.00e+000 norm(X), norm(y), norm(Z) = 3.2e+000, 1.5e+000, 1.9e+000 norm(A), norm(b), norm(C) = 3.9e+000, 4.2e+000, 2.6e+000 Total CPU time (secs) = 0.99 CPU time per iteration = 0.07 termination code = 0 DIMACS: 3.3e-012 0.0e+000 1.3e-012 0.0e+000 4.9e-009 4.9e-009- -Status: SolvedOptimal value (cvx_optval): -32. 程序代码:n=3;a=-3 -1 -3;b=2;5;6;C=2 1 1;1 2 3;2 2 1;cvx_begin variable x(n) minimize( a*x) subject to C * x =0cvx_end运行结果:Calling SDPT3 4.0: 6 variables, 3 equality constraints- num. of constraints = 3 dim. of linear var = 6* SDPT3: Infeasible path-following algorithms* version predcorr gam expon scale_data NT 1 0.000 1 0 it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime- 0|0.000|0.000|1.1e+001|5.1e+000|6.0e+002|-7.000000e+001 0.000000e+000| 0:0:00| chol 1 1 1|0.912|1.000|9.4e-001|4.6e-002|6.5e+001|-5.606627e+000 -2.967567e+001| 0:0:00| chol 1 1 2|1.000|1.000|1.3e-007|4.6e-003|8.5e+000|-2.723981e+000 -1.113509e+001| 0:0:00| chol 1 1 3|1.000|0.961|2.3e-008|6.2e-004|1.8e+000|-4.348354e+000 -6.122853e+000| 0:0:00| chol 1 1 4|0.881|1.000|2.2e-008|4.6e-005|3.7e-001|-5.255152e+000 -5.622375e+000| 0:0:00| chol 1 1 5|0.995|0.962|1.6e-009|6.2e-006|1.5e-002|-5.394782e+000 -5.409213e+000| 0:0:00| chol 1 1 6|0.989|0.989|2.7e-010|5.2e-007|1.7e-004|-5.399940e+000 -5.400100e+000| 0:0:00| chol 1 1 7|0.989|0.989|5.3e-011|5.8e-009|1.8e-006|-5.399999e+000 -5.400001e+000| 0:0:00| chol 1 1 8|1.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 58同城保姆合同范例
- 书包厂劳务合同范例
- 公司厂房销售合同样本
- 入住燕园合同范例
- 代买家具合同范例
- ktv协议合同范例
- 上门理发服务协议合同范例
- 国际商标注册代理及全球知识产权保护服务合同
- 民宿产业收益分成及运营管理合同
- 高精度工业金属无损检测胶片定期租赁服务合同
- 学生常见病预防
- 《路基养护》课件
- 2025年上海二手房买卖合同参考范文(2篇)
- 2025年全国大学生百科知识竞赛题库及答案(共740道题)
- 2025年全球及中国智能无人叉车行业头部企业市场占有率及排名调研报告
- 《基于EVA的科大讯飞企业价值评估的计算过程及结果探析案例报告》10000字(论文)
- 2025苏州中考数学二轮专题复习-圆的综合应用-专项训练【含答案】
- 空气输送斜槽选型手册
- 服装IE(浙江纺织服装职业技术学院)知到智慧树答案
- 糖尿病足疼痛
- 培训机构教务管理岗位职责
评论
0/150
提交评论