Error using horzcat in linprog

2 views (last 30 days)
Jacob Muvingi
Jacob Muvingi on 9 Aug 2019
Commented: Jacob Muvingi on 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

Answers (1)

Neuropragmatist
Neuropragmatist on 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,

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!