主题:【文摘】一道有趣的概率题 -- 天下第一银杏树
N = 1e3; % total # of runs
% behind door # 1 is the car. This configuration is fixed, while your draws are random.
Upick = ceil(3*rand(N,1)); % the door you picked in each of N runs.
P_no_swtch = length(find(Upick==1))/N; % probability of getting the car if you don't switch
SWTCH = [0, 3, 2;
3, 0, 1;
2, 1, 0]; % SWTCH(a,b) denotes the target door as you switch, when you have
% picked door #a, and the host has showed door #b.
P_swtch = 0; % Initialize: probability of getting the car if you do switch
for k = 1:N
host = ceil(3*rand(1)); % the host randomly picks a door, #1->#3
while host == Upick(k) || host ==1 % this door has to be different
host = ceil(3*rand(1)); % from your door, and it has to reveal a goat.
end
NewChoice= SWTCH(Upick(k), host);
if NewChoice == 1 % is a car
P_swtch = P_swtch + 1; % accumulate the hits
end
end
P_swtch = P_swtch/N;
%% Conclusion:
[P_no_swtch, P_swtch]
% == [0.3320, 0.6680], i.e., [1/3, 2/3]. Therefore switching is preferable.
本帖一共被 1 帖 引用 (帖内工具实现)
- 相关回复 上下关系8
不同意你,也不同意冷眼旁观 1 林小筑 字779 2005-08-05 19:33:11
disagree again 2 衲子 字1267 2005-08-05 20:46:30
I actually did manually list all cases. May I see your code pls? 林小筑 字0 2005-08-05 21:49:45
my annotated MATLAB code. How about ur manual list?
清楚了 1 林小筑 字2003 2005-08-06 00:22:50
I see. It all boils down to the question what is Omega? 衲子 字388 2005-08-06 01:16:06
应重新选择, 概率变大 1/3 -> 2/3, Monte Carlo verified 1 衲子 字321 2005-08-05 14:58:49
😜del landlord 字0 2005-08-05 15:17:59