1 view (last 30 days)

Show older comments

Hi,

this is part of my code and I have the problem at this line : Dmet(t,b)= min(I(t,b),D(t)- symsum(Dmet(t,b),a,1,b-1)) .

Maybe it is a stupid thing but I don't know how to fix it. Thanks!

for b=1:9

if b==1

Dmet(t,b)=min(I(t,b),D(t)); %Dmet(t) is the fraction of the total demand met with batch 1

Dleft(t,b)=D(t)-Dmet(t,b); %Dleft(t) is the fraction of the total demand that is not met yet and it will be with batches other than 1

else

Dmet(t,b)= min(I(t,b),D(t)- symsum(Dmet(t,b),a,1,b-1)) ;

Dleft(t,b)=D(t)-symsum(Dmet(t,b),a,1,b);

end

end

Shashwat Bajpai
on 10 Feb 2020

The problem maybe in the way Dmet is being set in the "if" condition ot the I variable maybe a column vector and thus is not taking b>1. Similarly if Dmet is column vector it won't be able to access (t,b). I would suggest add a breakpoint on the line generating the error and check the dimensions of the variables in use.

Hope this Helps!

Shashwat Bajpai
on 12 Feb 2020

Edited: Shashwat Bajpai
on 12 Feb 2020

I've made some changes to the code you sent. Please take a look:

N=10000;

T=365;

S=67 ;

for run=1:N

I(1,:)=zeros(1,365) ;

%DEMAND

D=gamrnd(49.6,1,[1 T]) ; %365 random numbers with gamma distribution

D=D.';

Dmet=zeros(1,365);

syms a;

for t=1:T

%PLACE THE ORDER AT THE BEGINNING OF THE DAY

Q(t)=S-sum(I(t)); %ordered boxes at time t that will end in the batch 1 of the day after

%MEETING THE DEMAND

for b=1:9

if b==1

Dmet(t,b)=min(I(b),D(t)); %Dmet(t) is the fraction of the total demand met with batch 1

Dleft(t,b)=D(t)-Dmet(t,b); %Dleft(t) is the fraction of the total demand that is not met yet

else

Dmet(t,b)= min(I(b),D(t)- symsum(Dmet(t,b),a,1,b-1)) ;

Dleft(t,b)=D(t)-symsum(Dmet(t,b),a,1,b);

end

end

end

end

Since you have initialized I as a row vector you do not need to give to values to access its elements, therfore i changed that. The second for loop runs from t=1:T this will run for 365 times and since you allocated I to be only a 1x9 vector it will run into an error. You also need to define the variable a which i declared as a symbol as you are using symsum. If pre-allocating Dmet doesn't work you can define it as a cell array and convert it back to a matrix after the looping is finally over.

Hope this Helps!

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

Start Hunting!