MATLAB大侠,速来帮帮我,看看这个程序哪里出错了,为什么运行不出来!

在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) %调用优化过程

好像是主程序有问题,可是我找不出来啊!,

懂的帮我改改!非常感谢

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,@confun,options)
在command window里输入如上程序。
注:这个程序就是把[x,fval,exitflag,output,lambda]=fmincon(@myfun,x0,[],[],[],[],lb, ub,@confun,options) 这段程序里的mycon 改成confun。错的原因就是调用m文件名写错了。
输出结果如下:
Active inequalities (to within options.TolCon = 1e-06):
lower upper ineqlin ineqnonlin
1 4

x =
17.000000000000000
27.887198025363730
3.756619594370988

fval =
5.562817664144011e+05
exitflag =
4
output =
iterations: 13
funcCount: 68
lssteplength: 1
stepsize: 1.572531012863474e-07
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 3.666915181383956e-04
constrviolation: 1.495625383540755e-07
message: [1x762 char]追问

,非常感谢哦!上面那个已经运行出来了!我还有个程序也有点问题,也是找不到原因,可不可以留个qq,给我指导一下啊!感激不尽哦,我qq是1099054396

温馨提示:答案为网友推荐,仅供参考
相似回答