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
温馨提示:答案为网友推荐,仅供参考