我用这个程序计算两阶段dea,在sheet1中更换不同年份的面板数据,更换一次用程序运行一次,2000-2003年的结果都可以计算得到,但是2004年开始就出现了这行的报错,不知道是什么原因 ,想问一下这个怎么解决
无法执行赋值,因为左侧的大小为 9×1,右侧的大小为 0×0。
出错 twostage_leader_follower (第 33 行)
w(:,i)=linprog(f,A,b,Aeq,beq,LB);
出错 HN (第 6 行)
[e1_1,e1_2,e2_1,e2_2,WLe1,WFe2,WFe1,WLe2]=twostage_leader_follower(X,Z,Y);
%函数程序:
function[e1_1,e1_2,e2_1,e2_2,WLe1,WFe2,WFe1,WLe2]=twostage_leader_follower(X,Z,Y);
[n,m]=size(X);
[n,d]=size(Z);
[n,s]=size(Y);
WLe1=zeros(n,m+d+s);
WFe2=zeros(n,m+d+s);
WFe1=zeros(n,m+d+s);
WLe2=zeros(n,m+d+s);
%part1
%stage 1 as leader
for i=1:n
Aeq=[X(i,:) zeros(1,s+d)];
beq=1;
f=[zeros(1,m) -Z(i,:) zeros(1,s)];
A=[-X Z zeros(n,s);zeros(n,m) -Z Y];
b=zeros(2*n,1);
LB=[zeros(1,m+s+d)]';
w(:,i)=linprog(f,A,b,Aeq,beq,LB);
WLe1(i,:)=w(:,i)';
e1_1(i,1)=-(f*w(:,i));
end
for i=1:n
Aeq=[zeros(1,m) Z(i,:) zeros(1,s);e1_1(i,1)*X(i,:) -Z(i,:) zeros(1,s)];
beq=[1;0];
f=[zeros(1,m+d) -Y(i,:)];
A=[-X Z zeros(n,s);zeros(n,m) -Z Y];
b=zeros(2*n,1);
LB=[zeros(1,m+s+d)]';
w(:,i)=linprog(f,A,b,Aeq,beq,LB);
WFe2(i,:)=w(:,i)';
e1_2(i,1)=-(f*w(:,i));
end
%part2
%stage 2 as leader
for i=1:n
Aeq=[ zeros(1,m) Z(i,:) zeros(1,s)];
beq=1;
f=[zeros(1,m+d) -Y(i,:)];
A=[-X Z zeros(n,s);zeros(n,m) -Z Y];
b=zeros(2*n,1);
LB=[zeros(1,m+s+d)]';
w(:,i)=linprog(f,A,b,Aeq,beq,LB);
WLe2(i,:)=w(:,i)';
e2_2(i,1)=-(f*w(:,i));
end
for i=1:n
Aeq=[X(i,:) zeros(1,s+d);zeros(1,m) e2_2(i,1)*Z(i,:) -Y(i,:)];
beq=[1;0];
f=[zeros(1,m) -Z(i,:) zeros(1,s)];
A=[-X Z zeros(n,s);zeros(n,m) -Z Y];
b=zeros(2*n,1);
LB=[zeros(1,m+s+d)]';
w(:,i)=linprog(f,A,b,Aeq,beq,LB);
WFe1(i,:)=w(:,i)';
e2_1(i,1)=-(f*w(:,i));
end
data=xlsread('C:\Users\Desktop\added data','Sheet1','C3:L16');
X=data(:,1:5);
Z=data(:,8:9);
Y=data(:,6:7);
[e1_1,e1_2,e2_1,e2_2,WLe1,WFe2,WFe1,WLe2]=twostage_leader_follower(X,Z,Y);
n=14;
dev=zeros(n,3);
dev(:,1)=e1_1-e2_1;%the deviation of upper bound and lower bound of stage 1
dev(:,2)=e2_2-e1_2;%the deviation of upper bound and lower bound of stage 2
for i=1:n
if dev(i,1)>dev(i,2);
dev(i,3)=1;
end
end
eff=zeros(n,4);
eff(:,1)=e1_1;
eff(:,2)=e2_1;
eff(:,3)=e1_2;
eff(:,4)=e2_2;
sheet=1;
xlswrite('efficiency.xlsx',eff,sheet);
sheet=2;
xlswrite('efficiency.xlsx',dev,sheet);
sheet=1;
xlswrite('Weights.xlsx',WLe1,sheet);
sheet=2;
xlswrite('Weights.xlsx',WFe2,sheet);
sheet=3;
xlswrite('Weights.xlsx',WFe1,sheet);
sheet=4;
xlswrite('Weights.xlsx',WLe2,sheet);