(1) Use simulation to generate 10000 service times and estimate the mean service time for you.
# We initialize the simulation
n = 10000
m1 = 3
m2 = 12
x = NULL
for (i in 1:n){
u = runif(1,0,1)
if(u <= 0.8){
x[i] = rexp(1, rate = 1/m1)
}
else{
x[i] = rexp(1, rate = 1/m2)
}
}
#We display the first 50 simulated data
x[1:50]
## [1] 0.29115283 1.68544801 3.10350257 13.28370904 5.34112035 0.16658892
## [7] 46.73578036 1.31659955 23.40742916 0.71609397 0.49002621 0.41533005
## [13] 25.47774412 6.85285528 3.01837855 0.45631714 2.36823174 0.98033805
## [19] 0.09874582 3.24383125 0.01995226 0.76424819 4.90741792 2.29523815
## [25] 0.81164696 0.80332199 5.35403302 6.63521811 6.42480393 2.30128466
## [31] 7.49389834 5.78008172 0.01463246 2.29142177 3.00730485 0.66488259
## [37] 4.55084131 3.24058223 10.26519730 0.21315953 1.02005324 0.07183387
## [43] 3.60714358 0.60291214 4.54389656 4.60169134 3.76280696 3.21794409
## [49] 3.46830654 0.76003559
#We display the simulated mean
mean(x)
## [1] 4.875537
# We calculate the theorical mean and we display it
y = 3 * 0.8 + 12 * 0.2
y
## [1] 4.8
(2) Summarize your data with R code hist(x, probability = TRUE) and mean(x), where x is an array representing your simulated data. Add to the histogram two vertical lines indicating the simulated mean and the theoretical mean.
Discussion
We can notice in this simulation that approximatively around ten thousands of the customers have been simulated by a distribution (exponential). it seems that in this project, the simulation has shown successful results since the probability of having the faster mechanic is 0.8 because looking at our results, simulated mean and theoretical mean are almost the same, getting close to 4.8 minutes. We can then conclude that the simulation was successful.