求MATLAB高手解救!为什么运行老是错误函数function f=myfun1(x);f=17.42+0.25*x(2)*(x(6)+2*x(7)+2*x(8)+x(9))-1.5*x(1)*(x(3)/2+x(4)+x(5)/2);约束function[c,ceq]=mycon(x);c(1)=x(4)/x(3)-5;c(2)=x(5)/x(4)-5;c(3)=x(7)/x(6)-5;c(4)=x(8)/x(7)-5;c
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/27 08:21:51
求MATLAB高手解救!为什么运行老是错误函数function f=myfun1(x);f=17.42+0.25*x(2)*(x(6)+2*x(7)+2*x(8)+x(9))-1.5*x(1)*(x(3)/2+x(4)+x(5)/2);约束function[c,ceq]=mycon(x);c(1)=x(4)/x(3)-5;c(2)=x(5)/x(4)-5;c(3)=x(7)/x(6)-5;c(4)=x(8)/x(7)-5;c
求MATLAB高手解救!为什么运行老是错误
函数function f=myfun1(x);
f=17.42+0.25*x(2)*(x(6)+2*x(7)+2*x(8)+x(9))-1.5*x(1)*(x(3)/2+x(4)+x(5)/2);
约束function[c,ceq]=mycon(x);
c(1)=x(4)/x(3)-5;
c(2)=x(5)/x(4)-5;
c(3)=x(7)/x(6)-5;
c(4)=x(8)/x(7)-5;
c(5)=x(9)/x(8)-5;
c(6)=1-x(1);
c(7)=1-x(2);
c(8)=17-x(3);
c(9)=17-x(4);
c(10)=17-x(5);
c(11)=17-x(6);
c(12)=17-x(7);
c(13)=17-x(8);
c(14)=17-x(9);
c(15)=130-1.414*x(2)*(x(6)/2+x(7)+x(8)+x(9)/2);
ceq(1)=x(5)-2*x(3);
ceq(2)=x(9)-2*x(6);
x0=[1.5;1.5;19;18;38;22;18;18;44];
lb=[1.5;1.5;17;17;17;17;17;17;17];
ub=[1.5;1.5;19;18;38;28;28;28;56];
[x,fval,exitflag,output,lambda]=fmincon(@myfun1,x0,[],[],[],[],lb,ub,@mycon)
求MATLAB高手解救!为什么运行老是错误函数function f=myfun1(x);f=17.42+0.25*x(2)*(x(6)+2*x(7)+2*x(8)+x(9))-1.5*x(1)*(x(3)/2+x(4)+x(5)/2);约束function[c,ceq]=mycon(x);c(1)=x(4)/x(3)-5;c(2)=x(5)/x(4)-5;c(3)=x(7)/x(6)-5;c(4)=x(8)/x(7)-5;c
约束条件改成这样的形式:
function [c,ceq]=mycon(x)
c=[x(4)/x(3)-5;
x(5)/x(4)-5;
x(7)/x(6)-5;
x(8)/x(7)-5;
x(9)/x(8)-5;
1-x(1);
1-x(2);
17-x(3);
17-x(4);
17-x(5);
17-x(6);
17-x(7);
17-x(8);
17-x(9);
130-1.414*x(2)*(x(6)/2+x(7)+x(8)+x(9)/2)];
ceq=[x(5)-2*x(3);
x(9)-2*x(6)];
%%%%%%%%%%%%%%%%%%%%
>> x0=[1.5;1.5;19;18;38;22;18;18;44];
lb=[1.5;1.5;17;17;17;17;17;17;17];
ub=[1.5;1.5;19;18;38;28;28;28;56];
options=optimset('LargeScale','off');
[x,fval,exitflag,output,lambda]=fmincon(@myfun1,x0,[],[],[],[],lb,ub,@mycon,options)
Optimization terminated: first-order optimality measure less than options.TolFun
and maximum constraint violation is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1 1 12
2 2 13
7 3 15
8 4
5
x =
1.5000
1.5000
19.0000
18.0000
38.0000
18.1946
17.0000
17.0000
36.3891
fval =
-41.2361
exitflag =
1
output =
iterations: 4
funcCount: 50
stepsize: 1
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 1.8852e-008
cgiterations: []
message: [1x143 char]
lambda =
lower: [9x1 double]
upper: [9x1 double]
eqlin: [0x1 double]
eqnonlin: [2x1 double]
ineqlin: [0x1 double]
ineqnonlin: [15x1 double]