>> f=[0;0;0;-0.77;-0.63;-0.70;-0.575];
A=[-1 0 0 0 0 0 0
1 0 0 0 0 0 0
0 -1 -1 0 0 0 0
0 1 1 0 0 0 0
0.2 0.85 1 0 0 0 0
0 0 0 7.5 6.1 9.0 7.35
0 0 0 1.4 0 1.65 0];
b=[0;8.2;0;3.5;9;96.5;7.5];
Aeq=[1 1 0 -1 -1 0 0
1 0 -1 0 0 1 1];
beq=[-2.5;8.2];
[x,fval,exitflag,output] = linprog(f,A,b,Aeq,beq)
Exiting: One or more of the residuals, duality gap, or total relative error
has stalled:
the dual appears to be infeasible (and the primal unbounded).
(The primal residual < TolFun=1.00e-008.)
x =
1.0e+021 *
0.0000
4.9454
-4.9454
4.9454
-0.0000
-4.1961
-0.7493
fval =
-4.3984e+020
exitflag =
-3
output =
iterations: 19
algorithm: 'large-scale: interior point'
cgiterations: 0
message: [1x217 char]
constrviolation: 9.1668e+005
firstorderopt: 8.7498e+019
应该还加个x,y>0
否则解有点问题
代码如下
>> f=[0;0;0;-0.77;-0.63;-0.70;-0.575];
A=[-1 0 0 0 0 0 0
1 0 0 0 0 0 0
0 -1 -1 0 0 0 0
0 1 1 0 0 0 0
0.2 0.85 1 0 0 0 0
0 0 0 7.5 6.1 9.0 7.35
0 0 0 1.4 0 1.65 0];
b=[0;8.2;0;3.5;9;96.5;7.5];
Aeq=[1 1 0 -1 -1 0 0
1 0 -1 0 0 1 1];
beq=[2.5;8.2];
lb=zeros(7,1);
[x,fval,exitflag,output] = linprog(f,A,b,Aeq,beq,lb)
Optimization terminated.
x =
8.2000
3.5000
0.0000
5.3571
8.8429
0.0000
0.0000
fval =
-9.6960
exitflag =
1
output =
iterations: 8
algorithm: 'large-scale: interior point'
cgiterations: 0
message: 'Optimization terminated.'
constrviolation: 4.4409e-014
firstorderopt: 1.2641e-009
max w+2=9.6960
w=7.6960
f=[0;0;0;-0.77;-0.63;-0.70;-0.575];
Aeq=[1 1 0 -1 -1 0 0;-1 0 1 0 0 -1 -1];
Beq=[-2.5;-8.2];
A=[0 1 1 0 0 0 0;
0 -1 -1 0 0 0 0;
0.2 0.85 1 0 0 0 0;
0 0 0 7.5 6.1 9.0 7.35;
0 0 0 1.4 0 1.65 0];
B=[3.5;0;9;96.5;7.5];
lb=[0;0;0;0;0;0;0];%下限都应该大于零吧?
ub=[8.2;inf ;inf; inf ;inf;inf;inf];
[x,fval,exitflag]=linprog(f,A,B,Aeq,Beq,lb,ub)
Max=-fval-2
zd0412_1
Optimization terminated.
x =
8.2000
3.5000
0.0000
5.3571
8.8429
0.0000
0.0000
fval =
-9.6960
exitflag =
1
Max =
7.6960
>>