Attachment 'Aufgabe3.m'

Download

   1 function Aufgabe3
   2 %Aufgabe3 - Simulate Monty-Hall-Problem and plot empirical evidence.
   3 %
   4 %usage
   5 %  Aufgabe3
   6 %
   7 %description
   8 %  Aufgabe3 simulates the Monty-Hall-Problem 10000 times and plots are pie-chart
   9 %  which indicates whether it is wise to switch doors or not.
  10 %
  11 %author
  12 %  buenau@cs.tu-berlin.de
  13 
  14 N = 10000;
  15 
  16 who_won = zeros(2, N);
  17 
  18 for i=1:N
  19   % Put price behind a random door.
  20   price = zeros(1,3);
  21   price(randint(1, 1, [1 3])) = 1;
  22  
  23   % Strategy 1: Choose door at random. 
  24   strat1_sel = randint(1, 1, [1 3]); 
  25 
  26   % Strategy 2: Switch to other door.   
  27   host_opens = randomchoice(setdiff(1:3, [ strat1_sel find(price) ]));
  28   strat2_sel = randomchoice(setdiff(1:3, [ strat1_sel host_opens ]));
  29 
  30   who_won(1, i) = price(strat1_sel);
  31   who_won(2, i) = price(strat2_sel);
  32 end
  33 
  34 pie(sum(who_won, 2) / N, { 'Strategy 1: Do not change', 'Strategy 2: Change doors' });
  35 title(sprintf('Frequency of wins for the two strategies in %d simulations', N));
  36 
  37 % Choose an element of vector a at random.
  38 function c = randomchoice(a)
  39 c = a(randint(1, 1, [1 length(a)]));

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-03-12 14:03:20, 1.5 KB) [[attachment:Aufgabe1.m]]
  • [get | view] (2009-03-12 14:03:20, 0.8 KB) [[attachment:Aufgabe2.m]]
  • [get | view] (2009-03-12 14:03:20, 1.0 KB) [[attachment:Aufgabe3.m]]
  • [get | view] (2009-03-12 14:03:20, 1.2 KB) [[attachment:Aufgabe4.m]]
  • [get | view] (2009-03-12 14:03:20, 1.5 KB) [[attachment:Aufgabe5.m]]
  • [get | view] (2009-03-12 14:03:20, 88.7 KB) [[attachment:ML_Praktikum_U01.pdf]]
  • [get | view] (2009-03-12 14:03:20, 89.4 KB) [[attachment:ML_Praktikum_U02.pdf]]
  • [get | view] (2009-03-12 14:03:20, 78.5 KB) [[attachment:ML_Praktikum_U03.pdf]]
  • [get | view] (2009-03-12 14:03:20, 96.2 KB) [[attachment:ML_Praktikum_U04.pdf]]
  • [get | view] (2009-03-12 14:03:20, 74.4 KB) [[attachment:ML_Praktikum_U05.pdf]]
  • [get | view] (2009-03-12 14:03:20, 86.7 KB) [[attachment:ML_Praktikum_U06.pdf]]
  • [get | view] (2009-03-12 14:03:20, 80.0 KB) [[attachment:Matlab_diary.txt]]
  • [get | view] (2009-03-12 14:03:20, 6.3 KB) [[attachment:U03_2gaussians.dat]]
  • [get | view] (2009-03-12 14:03:20, 15.6 KB) [[attachment:U03_5gaussians.dat]]
  • [get | view] (2009-03-12 14:03:20, 1020.4 KB) [[attachment:U04_datasets.zip]]
  • [get | view] (2009-03-12 14:03:20, 6.4 KB) [[attachment:U05_datasets.zip]]
  • [get | view] (2009-03-12 14:03:20, 60.1 KB) [[attachment:fishbowl.mat]]
  • [get | view] (2009-03-12 14:03:20, 22.7 KB) [[attachment:flatroll.mat]]
  • [get | view] (2009-03-12 14:03:20, 22.7 KB) [[attachment:flattroll.mat]]
  • [get | view] (2009-03-12 14:03:20, 343.4 KB) [[attachment:guide.pdf]]
  • [get | view] (2009-03-12 14:03:20, 32.8 KB) [[attachment:long_words.mat]]
  • [get | view] (2009-03-12 14:03:20, 7.6 KB) [[attachment:ratbert-debate.mat]]
  • [get | view] (2009-03-12 14:03:20, 45.3 KB) [[attachment:swissroll.mat]]
  • [get | view] (2009-03-12 14:03:20, 69.4 KB) [[attachment:tu_logo.mat]]
  • [get | view] (2009-03-12 14:03:20, 4053.5 KB) [[attachment:usps.mat]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.