简体   繁体   中英

Monte Carlo - Uniform Distribution

I have this problem:

Each week the three gas stations near your home sell at a price per gallon of X1, X2 and X3, respectively, where Xi are IID uniform random variables on [3.80, 4.20]. You purchase gas at the station with the lowest price. Use simple Monte Carlo methods to estimate average price per gallon of gas that you will pay, with the estimation error no larger than $0.05.

Can someone post an R code for this kind of problem or tell me how to approach this ?

Sure

Lets start with sampling

set.seed(12345)

n <- 1000
stationA <- runif(n, min=3.80, max=4.20)
stationB <- runif(n, min=3.80, max=4.20)
stationC <- runif(n, min=3.80, max=4.20)

whatIpay <- pmin(stationA, stationB, stationC)
avgIpay  <- mean(whatIpay)
stdIpay  <- sd(whatIpay)

now you have to figure out what value of n you need to get within desired error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM