Anda di halaman 1dari 4

A Quick Guide to R

Simulation

Download (Or use R in undergrad computer lab)


Go to https://www.r-project.org/
Select your preferred CRAN mirror and download R based on your
operation system.

Continuous Uniform Demand Simulation


# Setup parameters
Cp =2; Cv = 1; Cs = 0.5;
# How many random demands will be generated?
n = 100000;
#Generate n random demands from the uniform distribution
Demand = runif(n, min = 20, max = 40);
#Test the policy where we order 100/3 gallons for every period
y = 100/3;
mean(Cp*pmin(y,Demand) + Cs* pmax(y-Demand,0) - Cv*y)

Discrete Uniform Demand Simulation


# Setup parameters
Cp =1; Cv = 0.25; Cs = 0;
# How many random demands will be generated?
n = 100000;
#Generate n random demands from the discrete uniform distribution
Demand =
sample(c(5,10,15,20,25,30),n,replace=TRUE,c(1/8,1/8,1/8,1/8,1/4,1/4));
#Test the policy where we order 25 copies for every period
y = 25;
mean(Cp*pmin(y,Demand) + Cs* pmax(y-Demand,0) - Cv*y)

Anda mungkin juga menyukai