⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monty.m

📁 一些常被用于教学或者参考的概率论的实例的源代码
💻 M
字号:
%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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -