Error using horzcat in linprog

2 Ansichten (letzte 30 Tage)
Jacob Muvingi
Jacob Muvingi am 9 Aug. 2019
Kommentiert: Jacob Muvingi am 22 Aug. 2019
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

Antworten (1)

Neuropragmatist
Neuropragmatist am 9 Aug. 2019
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 Kommentar
Jacob Muvingi
Jacob Muvingi am 22 Aug. 2019
Metioche how best can i improve my code

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by