Error using horzcat in linprog

1 回表示 (過去 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 Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by