function costScenarios = SimulatePolicy(actionTable, demandProbs, ...
    orderCost, invPenalty, horizon, numScenarios, startState)

pd = makedist('Multinomial','probabilities',demandProbs);
demandScenarios = random(pd,numScenarios,horizon)-1;
costScenarios = zeros(numScenarios,1);
for k = 1:numScenarios
    state = startState;
    cost = 0;
    for t = 1:horizon
       % below, we add 1, since MATLAB indexing starts from 1, not 0
       order = actionTable(state+1, t);
       cost = cost + orderCost*order + ...
           invPenalty*(state + order - demandScenarios(k,t))^2;
       state = max(0, state + order - demandScenarios(k,t));
    end
    costScenarios(k) = cost;
end  % for 
