Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2010-03-27
帖子: 1
声望力: 0 ![]() |
![]()
我写的程序如下:
function f=myfun(x); f=(1/x(1)+5/12/x(2)+1/2/x(3)+7/24/x(4)+1/3/x(5))*conj(x(1))+(5/2/x(1)+1/x(2)+2/x(3)+5/12/x(4)+1/x(5))*conj(x(2))+(2/x(1)+1/2/x(2)+1/x(3)+1/2/x(4)+5/12/x(5))*conj(x(3))+(7/2/x(1)+5/2/x(2)+2/x(3)+1/x(4)+2/x(5))*conj(x(4))+(3/x(1)+1/x(2)+5/2/x(3)+1/2/x(4)+1/x(5))*conj(x(5)); end 上述程序保存为m文件; 然后运行下述程序: x0=[.2,.2,.2,.2,.2]; lb=[0,0,0,0,0]; ub=[1,1,1,1,1]; [x,fval,exitflag,output,lambda]=fmincon('fmin',x0,[],[],[1,1,1,1,1],1,lb,ub) 运行后,结论为 x = 1.0000 0 0.0000 -0.0000 0 fval = NaN exitflag = 0 output = iterations: 83 funcCount: 505 stepsize: 2 algorithm: 'medium-scale: SQP, Quasi-Newton, line-search' firstorderopt: Inf cgiterations: [] lambda = lower: [5x1 double] upper: [5x1 double] eqlin: NaN eqnonlin: [0x1 double] ineqlin: [0x1 double] ineqnonlin: [0x1 double] 这个结论明显不对,不知道哪里出问题了,用lingo做的结论如下: Local optimal solution found at iteration: 41 Objective value: 21.44022 Model Title: mix bottle Variable Value Reduced Cost x2 0.1529363 0.000000 x1 0.3844413 0.000000 x3 0.2411757 -0.1613561E-06 x4 0.8655592E-01 0.1089302E-06 x5 0.1348908 0.000000 Row Slack or Surplus Dual Price 1 21.44022 -1.000000 2 0.000000 -0.2149157E-04 3 0.3844413 0.000000 4 0.1529363 0.000000 5 0.2411757 0.000000 6 0.8655592E-01 0.000000 7 0.1348908 0.000000 为正确答案,请高手指出问题所在,及修改后的程序,谢谢!! |
![]() |
![]() |