简体   繁体   English

蒙特卡洛-均匀分布

[英]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]. 每周,您家附近的三个加油站分别以每加仑X1,X2和X3的价格出售,其中Xi是[3.80,4.20]上的IID统一随机变量。 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. 使用简单的蒙特卡洛方法估算您将支付的每加仑汽油平均价格,估算误差不超过$ 0.05。

Can someone post an R code for this kind of problem or tell me how to approach this ? 有人可以针对此类问题发布R代码,或告诉我该如何处理吗?

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 现在,您必须找出要在所需误差范围内得到的n值是多少

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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