共轭梯度法编程

上传人:wt****50 文档编号:37781984 上传时间:2018-04-22 格式:DOC 页数:13 大小:47.50KB
返回 下载 相关 举报
共轭梯度法编程_第1页
第1页 / 共13页
共轭梯度法编程_第2页
第2页 / 共13页
共轭梯度法编程_第3页
第3页 / 共13页
共轭梯度法编程_第4页
第4页 / 共13页
共轭梯度法编程_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《共轭梯度法编程》由会员分享,可在线阅读,更多相关《共轭梯度法编程(13页珍藏版)》请在金锄头文库上搜索。

1、P90 第二章 11(2) 用大 M 法求解min w=2x1+x2-x3-x4 s.t x1-x2+2x3-x4=22x1+x2-3x3+x4=6x1+x2+x3+x4=7xi0, i = 1, 2, 3, 4 用 matlab 求解如下:f=2,1,-1,-1,200,200,200; a=1 -1 2 -1 1 0 0;2 1 -3 1 0 1 0;1 1 1 1 0 0 1; b=2 6 7; lb=zeros(7,1); x,fval,exitflag,output,lambda=linprog(f,a,b,lb) Optimization terminated. 运行结果如下:x

2、=3.00000.00001.00003.00000.00000.00000.0000 fval =2.0000 exitflag =1 output = iterations: 7algorithm: large-scale: interior pointcgiterations: 0message: Optimization terminated. lambda = ineqlin: 0x1 doubleeqlin: 3x1 doubleupper: 7x1 doublelower: 7x1 double 从上述运行结果可以得出:最优解为 x= ,最小值约为 f*=2。P151 第三章 2

3、6 用共轭梯度算法求 f(x) = (x1-1)2+5*(x2-x12)2 的极小点,取初始点 x0= 。 用 matlab 求解如下:function mg=MG()% %共轭梯度法求解习题三第 26 题% clc; clear; n=2; x=2 0; max_k=100; count_k=1; trace(1,1)=x(1); trace(2,1)=x(2); trace(3,1)=f_fun(x); k=0; g1=f_dfun(x); s=-g1; while count_k0.001 g(2,1)=1; elseif a=0g(1,1)=1+2*M*(-x(1)2+x(2)*(-2

4、*x(1);g(2,1)=1+2*M*(-x(1)2+x(2); elseif a=0 elseif a=0 elsep=a2+b2; end%题 8(1) 运行结果如下:x =1.0e-004 *-0.2058-0.2058 f =-2.0576e-005 k =5 trace =100.0000 -0.0050 -0.0017 -0.0006 -0.0002 -0.0001 -0.0000 3.0000 -0.0050 -0.0017 -0.0006 -0.0002 -0.0001 -0.0000 从上述运行结果可以得出:最优解为 x= ,最小值约为 f*=0。(2) min f(x) =

5、 x12+x22S.t 2x1+x2-20-x2+10 用 matlab 求解如下: 主程序与(1)相同; 注意:以下三个函数体在运行计算习题四第 8(2)题时使用%* function g=f_dfun(x) global M; a=-2*x(1)-x(2)+2;b=x(2)-1; if a=0g(2,1)=2*x(2); elseif a=0g(1,1)=2*x(1)+2*M*(-2*x(1)-x(2)+2)*(-2);g(2,1)=2*x(2)+2*M*(-2*x(1)-x(2)+2)*(-1); elseif a=0 elseif a=0 elsep=a2+b2; end%题 8(2)

6、 运行结果如下:x =-0.00001.0000 f =1.0000 k =6 trace =100.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 3.0000 0.9901 0.9967 0.9989 0.9996 0.9999 1.0000 1.0000 从上述运行结果可以得出:最优解为 x= ,最小值约为 f*=1。P232 第四章 25 用梯度投影法求解下列线性约束优化问题min f(x) = x12+x1*x2+2*x22+2*x32+2*x2*x3+4*x1+6*x2+12*x3 s.t x1 + x2 +

7、 x3 6 x1x2 +2x3 2 xi0 , i = 1, 2, 3 取 x1= , 用 matlab 求解如下:f=x12+x1*x2+2*x22+2*x32+2*x2*x3+4*x1+6*x2+12*x3; a=1 1 1;1 1 -2; b=6;-2; l=zeros(3,1); x0=1 1 3; x,fval,exitflag,output,lambda,grad,hessian=fmincon(f,x0,a,b,l,)运行结果如下:x =0 0 1 fval =14 exitflag =1 output = iterations: 2funcCount: 14stepsize:

8、1algorithm: medium-scale: SQP, Quasi-Newton, line-searchfirstorderopt: 0cgiterations: message: 1x144 char lambda = lower: 3x1 doubleupper: 3x1 doubleeqlin: 0x1 doubleeqnonlin: 0x1 doubleineqlin: 2x1 doubleineqnonlin: 0x1 double grad =4.00008.000016.0000 hessian =1.1146 0.6771 0.60420.6771 3.3646 2.4

9、7920.6042 2.4792 3.4583 从上述运行结果可以得出:最优解为 x= ,最小值约为 f*=14。P234 第四章 34(1) 用乘子法求解max f(x) = 10x1+4.4x22 +2x3 s.t x1+4x2+5x332x1+3x2+2x329x32/2+x223x12, x20, x30 用 matlab 求解如下:function x,minf = ymh434(l) format long; syms x1 x2 x3 f=10*(x1)+4.4*(x2)2+2*(x3); h=-x1-4*x2-5*x3+32,-x1-3*x2-2*x3+29,(x3)2)/2+

10、(x2)2-3,x1-2,x2,x3; x0=2 2 0; v=1 0 0 0 0 0; M=2; alpha=2; gama=0.25; var=x1 x2 x3; eps=1.0e-4; if nargin = 8eps = 1.0e-4; end m1 = transpose(x0); m2 = inf; while lFE = 0;u=subs(h,x1,x2,x3,m1(1),m1(2),m1(3); for i=1:length(h)if (v(i)+M*u(i)= gamaM = alpha*M;x1 = x2;elsev = v - M*transpose(Hx2);x1 =

11、x2;endend end minf = Funval(f,var,x); format short; 运行结果如下:x =19.75 0 2.45 minf =-202.42 maxf1 =202.42 从上述运行结果可以得出:最优解为 x= ,最大值约为 f*=202.42, 最小值约为 f*=- 202.42。P235 第四章 35(2) 用序列二次规划法求解min f(x)=-5x1-5x2-4x3-x1x3-6x4-5x5/(1+x5)-8x6/(1+x6)-10(1-2e-x7+e-2x7) s.t g1(x)=2x4+x5+0.8x6+x7-5=0g2(x)=x22+x32+x5

12、2+x62-5=0g3(x)=x1+x2+x3+x4+x5+x6+x710g4(x)=x1+x2+x3+x45g5(x)=x1+x3+x5+x62-x72-50xi0, i=1,2,7 用 matlab 求解如下:function f=objfun35(x) f=-5*x(1)-5*x(2)-4*x(3)-x(1)*x(3)-6*x(4)-5*x(5)/(1+x(5)-8*x(6)/(1+x(6)-10*(1- 2*exp(-x(7)+exp(-2*x(7); function c,ceq = confun35(x) ceq=x(2)2+x(3)2+x(5)2+x(6)2-5; c=x(1)+

13、x(3)+x(5)+x(6)2-x(7)2-5;clc clear x0=1,1,1,1,1,1,1; aeq=0,0,0,2,1,0.8,1; beq=5; a=1,1,1,1,1,1,1;1,1,1,1,0,0,0; b=10,5; lb=0,0,0,0,0,0,0; ub=; x,fval,exitflag,output,lambda,grad,hessian=fmincon(objfun35,x0,a,b,aeq,beq,l b,ub,confun35,options) c,ceq=confun35(x) 运行结果如下:Iter F-count f(x) constraint Step

14、-size derivative optimality Procedure 0 8 -31.4958 1 Infeasible start point1 17 -41.7175 0.8642 1 -6.3 1.62 2 26 -43.0309 0.5358 1 -1.09 0.924 3 35 -44.5199 0.8348 1 -1.4 0.438 4 44 -44.4543 0.04621 1 0.126 0.247 5 53 -44.4636 0.004354 1 -0.00456 0.127 6 62 -44.4697 0.005324 1 -0.0007 0.00717 7 71 -44.4687 1.631e-005 1 0.000984 0.000523 8 80 -44.4687 6.73

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

当前位置:首页 > 生活休闲 > 社会民生

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