function [AVE_DAILY_COST] = simulate(num_runs, delivery_interval, delivery_quantity) 

NUM_DAYS = 365
TRUCK_CAPACITY=4000;%tires
truck_charge = 400;%delivery cost per truck
delivery_charge = truck_charge*(floor((delivery_quantity-1)/TRUCK_CAPACITY)+1);
penalty = 1000;%10 dollar penalty per day * 1000 tires 

for i = 1:num_runs    
    day_counter = 0;
    %Assume there is a delivery at the outset
    NUM_TIRES = delivery_quantity;%init 
    COST =delivery_charge;
    interest_rate = 0.01;
    days_without_tires =0;
    delivery_counter = 0;
    
    daily_inventory(1) = NUM_TIRES;

    while day_counter <= NUM_DAYS;
        if delivery_counter == delivery_interval;%add delivery charge
            NUM_TIRES = NUM_TIRES + delivery_quantity;
            COST = COST + delivery_charge;
            delivery_counter = 0;
        end
        NUM_TIRES = NUM_TIRES - flatdemand; %sell tires for day
       
        if NUM_TIRES <=0;%out of stock?
            days_without_tires = days_without_tires + 1;
            NUM_TIRES = 0;
        end    
        COST = COST + interest_rate*NUM_TIRES;%add charges for unsold tires
        day_counter = day_counter + 1;
        daily_inventory(day_counter+1) = NUM_TIRES;
        delivery_counter = delivery_counter + 1;
    end
    %add daily charge due interest at end of day for remaining tires
    cost_penalty = days_without_tires*10000;
    AVE_DAILY_COST(i) = (COST + cost_penalty)/NUM_DAYS;
end
plot(daily_inventory)
xlabel('days in simulation')
ylabel('number of tires in stock')
days_without_tires 