monty.m
来自「一些常被用于教学或者参考的概率论的实例的源代码」· M 代码 · 共 35 行
M
35 行
%monty.m/created by PJNahin for "Duelling Idiots"(4/8/99)
%This m-file simulates 10,000 games of "Let's Make A Deal."
%
%
rand('state',100*sum(clock))
WNS=0; %initialize number of games won with NO SWTICHING;
WWS=0; %initialize number of games won WITH SWITCHING;
switch1=1/3;
switch2=2/3;
for game=1:10000
choice=rand; %put the prize behind one of the three doors;
if choice <= switch1
prize=1;
elseif choice <= switch2
prize=2;
else
prize=3;
end
choice=rand;
if choice <= switch1 %pick a door;
select=1;
elseif choice <= switch2
select=2;
else
select=3;
end
if select==prize %if prize is behind your selection, then ...
WNS=WNS+1; %you win prize if you DON'T switch;
else %if prize is not behind your selection, then ...
WWS=WWS+1; %you win prize if you DO switch;
end
end
WWS
WNS
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?