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

📄 thief.m

📁 一些常被用于教学或者参考的概率论的实例的源代码
💻 M
字号:
%thief.m/created by PJNahin for "Duelling Idiots"(11/14/98)
%This m-file simulates "The Thief of Baghdad" problem for
%10,000 thieves.
%
%
rand('state',100*sum(clock))      %set new generator seed;
long=3;                           %time duration of long tunnel;
short=1;                          %time duration of short tunnel;
total=0;                          %total prison time for all thieves;
p1=1/3;
p2=2/3;
for thiefn=1:10000
   time=0;                        %initialize prison time for current
                                  %thief;
   trytoescape=1;                 %set flag for thief about to choose
                                  %a door for the first time;
     while trytoescape>0
        door=rand;
        if door<p1                %thief escapes,
           total=total+time;      %so up-date total prison time;
           trytoescape=0;         %reset flag to break while loop;
        elseif door<p2            %thief picks short tunnel and so
           time=time+short;       %up-date current thief's prison time;
        else
           time=time+long;        %thief picks long tunnel;
        end
     end
  end
  total/10000                     %print average time in prison
                                     
   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -