> 数学 >
R语言.写ocde的问题
Q1: 用R模拟500灯泡,每个能用的几率是0.99,1代表能用, 0代表不能用.
我目前只会那个 guess
人气:385 ℃ 时间:2020-03-22 04:04:47
解答
Q1不知道你想求什么,是想求最后还能用灯泡的个数么.那直接一句话就可以了.用二项分布随机数,你整个function就是在做二项分布随机数.>rbinom(10,500,0.99) #做10次试验,500个灯泡,每个灯泡的故障率是0.01[1] 495 495 ...Q1: simulates 500 light bulbs, each has prob. 0,99 of working. Using simulation, estimate the expected value and variance of the random variable X, which is 1 =light bulb works and 0 = does not work.estimate the expected value and variance of the random variable X这才是问题啊。
求最后还亮的灯泡数目的期望和方差。期望就是EX=1/n*一堆X的求和这里的X就是

[1] 495 495 495 494 492 494 499 493 495 491 但是n最好能大一点,你试试n=30,效果就很好了。理论期望是500×0.99=495模拟期望是EX=1/n*一堆X的求和=mean(rbinom(30,500,0.99)
我试了试,答案是494.6.如果你把n提到300,那么这个数会更接近。模拟方差就用样本方差,理论方差是500×0.99×0.01 你可以看看两者是否接近。

你这是一门课吗
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版