在Matlab中首先编写目标函数的M文件 myfun.m,返回x处的函数值f:
function f = myfun(x)
f=4.891*x(1)^2*x(2)*x(3)^2;
由于约束条件中有非线性约束,所以需要编写一描述非线性约束条件的M文件mycon.m:
function[c,ceq]=confun(x)
c(1)=5*x(3)-x(2);
c(2)=x(2)-17*x(3);
c(3)=750937.3/(x(1)*x(2)*sqrt(x(3)))-1250;
c(4)=6690340.8/(x(1)*x(2)*x(3)^2)-1000;
ceq=[];
最后在command window里输入:
options=optimset('largescale','off'); %采用标准算法
x0 = [24; 52; 5]; % 给定初值
lb=[17 ;10 ; 2];ub=[25 ;60; 6]; %给定变量的上、下限约束
[x,fval,exitflag,output,lambda]=fmincon(@myfun,x0,[],[],[],[],lb,...
ub,@mycon,options) %调用优化过程
好像是主程序有问题,可是我找不出来啊!,
懂的帮我改改!非常感谢
,非常感谢哦!上面那个已经运行出来了!我还有个程序也有点问题,也是找不到原因,可不可以留个qq,给我指导一下啊!感激不尽哦,我qq是1099054396