Help! Keep getting error index exceeds the number of array elements(0).
古いコメントを表示
% function [meanTot, stdTot] = RQpolicy_no(R1)
% Inventory system applying (R,Q) policy.
% Given reorder points, the function returns mean total cost and standard deviation.
function [meanTot, stdTot] = RQ_Test(R1)
n = 10; % Number of runs
lambda = 10; % Demand rates
L = 1; % Lead times
b = 20; % Backorder cost
h = 1; % Holding cost
A = 100; % Order cost
% The batch quantities by the EOQ formula
Q1 = round(sqrt(2*A*lambda/h));
costVector = []; % Vector with total cost for the runs
summa = 0; % Sum of total costs for all runs
for j = 1:n
% Creates points in time when demand will occur for each warehouse
% Times between customers are exp(lambda) distributed
nbrOfEvents = 30000;
u = rand(1,nbrOfEvents);
y = -log(1-u)/lambda;
T = cumsum(y);
stopTime = min(T(nbrOfEvents));
time = 0;
invLevel = 0; % Inventory levels
invPos = 0; % Inventory positions
invTime = []; % Arrival times for units in inventory
incom = []; % Arrival times for incoming items
backTime = []; % Times when backorders have occurred
timeInStock = 0; % Accumulated time in stock
54
timeInBackorder = 0; % Accumulated time in backorder
orderCost = 0; % Cost for all orders during simulation
Ntot = 0; % Number of customers during simulation
N1 = 0; % Number of backorders during simulation
% The first tenth of the time is start-up time
transientTime = stopTime/10;
while time < stopTime,
if time < transientTime,
timeInStock = 0;
timeInBackorder = 0;
end
% A trick to determine the next event
if isempty(incom),
incom = realmax;
end
% Determines the next event and the time when it happens
[time, event] = min([T(1) incom(1)]);
if incom(1) == realmax,
incom = [];
end
% A customer arrives at retailer 1
if event == 1,
Ntot = Ntot + 1;
% If there is stock on hand
if invLevel >= 1,
timeInStock = timeInStock + time - invTime(1);
invTime = invTime(2:length(invTime));
invLevel = invLevel - 1;
invPos = invPos - 1;
% Orders new items while the inventory position is less than R
55
while invPos <= R1,
orderCost = orderCost + A;
invPos = invPos + Q1;
for k = 1:Q1
incom = [incom time+L1];
end
end
% If there are no items in stock, the demanded item is backordered
else
N1 = N1 + 1;
backTime = [backTime time];
invLevel = invLevel - 1;
invPos = invPos - 1;
% Orders new items while the inventory position is less than R
56
while invPos <= R1,
orderCost = orderCost + A;
invPos = invPos + Q1;
for k = 1:Q1
incom = [incom time+L];
end
end
end
T = T(2:length(T));
end
if ~isempty(invTime),
for k = 1:length(invTime),
timeInStock = timeInStock + time - invTime(1);
invTime = invTime(2:length(invTime));
end
end
end
57
%%Partition%%
if ~isempty(backTime),
for k = 1:length(backTime),
timeInBackorder = timeInBackorder + time - backTime(1);
backTime = backTime(2:length(backTime));
end
end
end
stopTime = stopTime - transientTime;
% fillrate1 = 1 - N1/N1tot;
% The costs are calculated
orderCost = orderCost/stopTime;
holdCost = timeInStock*h/stopTime;
backCost = timeInBackorder*b/stopTime;
totCost = orderCost + holdCost + backCost;
costVector = [costVector totCost];
summa = summa + totCost;
% fillVector1 = [fillVector1 fillrate1];
meanTot = (1/n*summa);
end
Could someone help me with this? I have no idea why this is really happening!
4 件のコメント
Ardit Mehmeti
2020 年 2 月 23 日
Matt J
2020 年 2 月 23 日
How do we reproduce the error.
Eleanor Betton
2020 年 2 月 24 日
What is R1?
Maadhav Akula
2020 年 3 月 4 日
It would be helpful if you can specify the error message and your inputs to the function, to reproduce the error.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!