Error using horzcat in linprog

조회 수: 8 (최근 30일)
Jacob Muvingi
Jacob Muvingi 2019년 8월 9일
댓글: Jacob Muvingi 2019년 8월 22일
min sum(sj)
s.t W.Xd=1
U.Yd=E*d
U.Yj-W.Xj+sj=0
U,W>0
sj>0
sj=W.Xj-U.Yj
suppose x=[ 15 47009
5 18819
5 20506]
Y=[15 26 26151
15 61 25 7976
16 33 52 10649];
i manually determined sj, and use z to represent sj, hence z=[0 ; 0; 0].
i also sepately determined e for efficiency, and use e=[1; 1; 1]
m=size(X,3);
n=size(X,1);
s=size(Y,4);
v=size(z,1);
u=size(e,1);
for d=1:n
f=-[zeros(1,2) sum(z(d,:))];
A=[];
b=[];
Aeq=[zeros(1,2) X(d,:) zeros(1,3) ; Y(d,:) zeros(1,2) zeros (1,3) ; Y -X zeros(1,2) zeros(1,3)]
b=[1; e; 0]
lb=[zeros(m+s,1)];
ub=[];
[W(:d), fval]= linprog(f,A,b,Aeq,beq,lb,ub);
for j=1:n
Edj(d,j)=Y(j,:)*W(1:s,d) / (X(j,:)*W(s+1:s+m,d));
end
end
when i run it i am getting the message , Error using horzcat
Dimensions of arrays being concatenated are not consistent

답변 (1개)

Neuropragmatist
Neuropragmatist 2019년 8월 9일
It's hard to read your answer, please look at this first next time:
But, looking at your code I think the first problem is here:
Aeq=[zeros(1,2) X(d,:) zeros(1,3) ; Y(d,:) zeros(1,2) zeros (1,3) ; Y -X zeros(1,2) zeros(1,3)]
This will not work because X has only one row and when d>1 in your loop your code will crash. Also X and Y are different sizes so this concatenation will never work anyway because Aeq would have differently sized rows.
Hope this helps,
  댓글 수: 1
Jacob Muvingi
Jacob Muvingi 2019년 8월 22일
Metioche how best can i improve my code

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by