资源描述:
《matlb数学实验胡良剑第十,十一十二章部分答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第十章第一题f=[-3;4;-2;5];A=[1,1,3,-1;2,-3,1,-2];b=[14;-2];Aeq=[4,-1,2,-1];beq=-2;i=1:3;lb(i)=zeros(3,1);lb(4)=-inf;[x,feval]=linprog(f,A,b,Aeq,beq,lb)Optimizationterminated.x=0.00008.00000.0000-6.0000feval=2.0000第二题f=[5;4;8];A=[2,-1,0;5,3,0];b=[4;15];Aeq=[1,2,1];beq=6;lb=[0,0,0];[x,feval]=linprog(f,A,b
2、,Aeq,beq,lb)Optimizationterminated.x=0.00003.00000.0000feval=12.0000第五题clearf=-[7,12];A=[9,5;4,5;3,10];b=[360;200;300];lb=[0;0];[x,feval]=linprog(f,A,b,[],[],lb)Optimizationterminated.x=20.000024.0000feval=-428.0000在对求出的最小值取反既可以得出最大值为428第六题%%变量x1,x2,x3,x4,x5,x6;分别代表x11,x12,x13,x21,x22,x23%%xij表示是煤
3、场i对于居民地j的出生煤量。f=[10,5,6,4,8,12];lb=zeros(6,1);Aeq=[1,1,1,0,0,0;0,0,0,1,1,1;1,0,0,1,0,0;0,1,0,0,1,0;0,0,1,0,0,1;];beq=[60;100;50;70;40];[x,fval]=linprog(f,[],[],Aeq,beq,lb)Optimizationterminated.x=0.000020.000040.000050.000050.00000.0000fval=940.0000第十一题编写函数functionf=ex11fun(x);f=x(1)+x(2);%编写约束函数M
4、函数function[c,ceq]=confun(x)%非线性不等式约束c=[1.805-(4+(x(2)-7)/x(1))*(1-(4-x(2))/x(1));0.9025-(4-(7-x(2)))/(3*x(1));0.9025-(1-(4-x(2)))/(2*x(1)/3)];%非线性等式的约束ceq=[];最后在窗口运行:[x,feval]=fmincon(@newch11_fun,[1,1],[],[],[],[],[0,0],[],@newch11_confun)Warning:Large-scale(trustregion)methoddoesnotcurrentlysolv
5、ethistypeofproblem,switchingtomedium-scale(linesearch).>Infminconat260Optimizationterminated:first-orderoptimalitymeasurelessthanoptions.TolFunandmaximumconstraintviolationislessthanoptions.TolCon.Activeinequalities(towithinoptions.TolCon=1e-006):lowerupperineqlinineqnonlin12x=0.67814.8359feval=5.
6、5140第十二题首先%编写目标函数M函数functionf=ch12_fun(x)%目标函数f=-x(1)*x(2)*x(3)其次%编写约束函数M函数function[c,ceq]=ch12_confun(x)%非线性不等式约束c=[];%非线性等式的约束ceq=[];最后窗口运行A=[1,-2,-2;1,2,2];b=[0;72];Aeq=[1,-1,0];beq=10;[x,fval]=fmincon(@ch12_fun,[25,15,8],A,b,Aeq,beq,[0,10,0],[Inf,20,Inf],@ch12_confun)第十一章第一题:先编写Matlab程序枚举法IntL
7、p.m:function[x,y]=IntLp(f,G,h,Geq,heq,lb,ub,x,id,options)%整数线性规划分支定界法,可求解全整数线性或混合整数线性规划%y=minf'*xsubjectto:G*x<=hGeq*x=heqx为全整数%数或混合整数列向量%用法%[x,y]=IntLp(f,G,h)%[x,y]=IntLp(f,G,h,Geq,heq)%[x,y]=IntLp(f,G,h,Geq,heq