Thank you Alan. I figured it out myself today. The problem was to implement the I(t-1,k) to the linear equality condition. I wanted to have the condition
I(t-1,k) + Q(t,k) - I(t,k) = d(t,k)
Which will set the previous stock I(t-1,k) plus the amount of units produced in this period Q(t,k) minus the left amount of units, which will be stored, equal to the demand of the current period d(t,k) I solved the problem:
% Demand is satisfied
for ii = 1:T
for jj = 1:K
xtemp = clearer2;
xtemp(ii,jj) = -1; % Every I(t,k) * -1
xtemp2 = clearer3;
xtemp2(ii,jj) = 1; % Every Q(t,k)
if(ii > 1)
xtemp(ii - 1,jj) = 1; % Every I(t-1,k)
else
xtemp(1,jj) = -1; % First period there is no I(t-1,k)
end
xtemp = sparse([clearer12;xtemp(:);xtemp2(:)]'); % Change to sparse row
Aeq(counter,:) = xtemp'; % Fill in
beq(counter) = d(ii,jj);
counter = counter + 1;
end
end