t****g 发帖数: 35 | 1 There are four doors, and a prize of $1000 is placed behind one of these
doors.
First, you randomly choose a door, which has 25% chance of selecting the
prize door.
Second, someone opens a door which is not the door you chose and not the
door with the prize. Third, after seeing the empty door, you are asked if
you want to switch to another door.
Write a program to simulate this game 100,000 times and calculate the
probability of choosing the prize door if you switch your initially selected
door.
(Bonus question) As a follow up, how does the probability change if there
are 20 doors instead of 4? what if there are 1,000 doors and 13 of them
have $1,000 prizes?
用Matlab可以编的 |
g*****k 发帖数: 623 | 2 这要模拟干吗?直接有公式解
selected
【在 t****g 的大作中提到】 : There are four doors, and a prize of $1000 is placed behind one of these : doors. : First, you randomly choose a door, which has 25% chance of selecting the : prize door. : Second, someone opens a door which is not the door you chose and not the : door with the prize. Third, after seeing the empty door, you are asked if : you want to switch to another door. : Write a program to simulate this game 100,000 times and calculate the : probability of choosing the prize door if you switch your initially selected : door.
|
t****g 发帖数: 35 | 3 题目要求模拟....
【在 g*****k 的大作中提到】 : 这要模拟干吗?直接有公式解 : : selected
|
d*****e 发帖数: 7368 | 4 my simulation gives 0.37337
I am a newbie here, not in matlab, but in C.
Where is the equation/formula? |
a*******1 发帖数: 1554 | 5 P(get the prize) = P(get the prize|select wrong door at first)*P(select
wrong door at first)
= P(get the prize|select wrong door at first)*(3/4)
= (1/2)*(3/4)
= 3/8
因为如果一开始选对了那么换了之后就错了,所以要拿奖前提是开始选错了。既然开始
错了,对方又开了一个错的,那么剩下两个其中一个是对的,所以1/2
for 20 doors
P(get the prize) = P(get the prize|select wrong door at first)*P(select
wrong door at first)
= P(get the prize|select wrong door at first)*(19/20)
= (1/18)*(19/20)
= 0.052778
for 1000 doors with 13 prizes,
P(get the prize) = P(get the prize|select wrong door at first)*P(select
wrong door at first)+P(get the prize|select right door at first)*P(select
right door at first)
= P(get the prize|select wrong door at first)*987/1000+
P(get the prize|select right door at first)*13/1000
=(13/998)*(987/1000)+(12/998)*(13/1000)
= 0.013013
给我包子吧!!! |
t****g 发帖数: 35 | 6 怎么给包子,你的算法是在第二个知道那个门后不是钱的前提下的,其实我知道怎么算
,只是不会编程
【在 a*******1 的大作中提到】 : P(get the prize) = P(get the prize|select wrong door at first)*P(select : wrong door at first) : = P(get the prize|select wrong door at first)*(3/4) : = (1/2)*(3/4) : = 3/8 : 因为如果一开始选对了那么换了之后就错了,所以要拿奖前提是开始选错了。既然开始 : 错了,对方又开了一个错的,那么剩下两个其中一个是对的,所以1/2 : for 20 doors : P(get the prize) = P(get the prize|select wrong door at first)*P(select : wrong door at first)
|
d*****e 发帖数: 7368 | 7 thanks, it's very clear.
【在 a*******1 的大作中提到】 : P(get the prize) = P(get the prize|select wrong door at first)*P(select : wrong door at first) : = P(get the prize|select wrong door at first)*(3/4) : = (1/2)*(3/4) : = 3/8 : 因为如果一开始选对了那么换了之后就错了,所以要拿奖前提是开始选错了。既然开始 : 错了,对方又开了一个错的,那么剩下两个其中一个是对的,所以1/2 : for 20 doors : P(get the prize) = P(get the prize|select wrong door at first)*P(select : wrong door at first)
|
A****s 发帖数: 129 | 8 编这个不是很简单吗?
【在 t****g 的大作中提到】 : 怎么给包子,你的算法是在第二个知道那个门后不是钱的前提下的,其实我知道怎么算 : ,只是不会编程
|
f*******y 发帖数: 52 | 9 I think the simulation should be run under two scenarios: switch and not
switch. Then you can get two probabilities and compare. |