程序编的非常好,只有一句:size(x) = [4,3]改为x =zeros(4,3) 即可。
%=================================
function fff
clear;clc;
A= [1,1,1,0,0,0,0,0,0,0,0,0;
0,0,0,1,1,1,0,0,0,0,0,0;
0,0,0,0,0,0,1,1,1,0,0,0;
0,0,0,0,0,0,0,0,0,1,1,1;
-1,0,0,-1,0,0,-1,0,0,-1,0,0;
0,-1,0,0,-1,0,0,-1,0,0,-1,0;
0,0,-1,0,0,-1,0,0,-1,0,0,-1]
b=[200-1.645*10;
300-1.645*10;
400-1.645*10;
200-1.645*10;
-100-1.645*10;
-300-1.645*10;
-400-1.645*10]
x0=[0,0,0,0,0,0,0,0,0,0,0,0];
lb=[0,0,0,0,0,0,0,0,0,0,0,0];
ub=[];
[X,FVAL,EXITFLAG]=fmincon(@myobj,x0,A,b,[],[],lb,ub)
function f=myobj(x)
c = [12 21 21; 13 20 23; 15 17 27; 17 19 31];
x =zeros(4,3)
y = c.*x;
y = sum(y(:));
s = 0;
for i = 1:4
sg = sum(x(i,:));
s = s+sg.^0.6;
end
f = y+200*s;
%=============================
运行结果:
X =
19.5167 69.5167 94.5167 38.7083 88.7083 113.7083 38.7083 88.7083 113.7083 19.5167 69.5167 94.5167
FVAL =
0
EXITFLAG =
1
Global optimal solution found.
Objective value: 112550.5
Objective bound: 112550.4
Infeasibilities: 0.000000
Extended solver steps: 83
Total solver iterations: 4753
Variable Value Reduced Cost
X1 50.65000 0.000000
X2 0.000000 7.000000
X3 132.9000 0.000000
X4 0.000000 3.438348
X5 0.000000 8.438348
X6 283.5500 0.000000
X7 65.80000 0.000000
X8 316.4500 0.000000
X9 0.000000 0.1050611E+09
X10 0.000000 2.000000
X11 0.000000 2.000000
X12 0.000000 0.1050611E+09
Row Slack or Surplus Dual Price
1 112550.5 -1.000000
2 0.000000 3.000000
3 0.000000 5.438348
4 1.300000 0.000000
5 183.5500 0.000000
6 0.000000 -215.0000
7 0.000000 -217.0000
8 0.000000 -40.97349