function ThreeDoors(n,it) %function ThreeDoors(n,it) % % n = number of doors % it = number of iterations % the showmaster will always open n-2 doors that do not contain the price. if nargin < 2 it = 1000; end if nargin < 1 n = 3; end not_switch_count = 0; switch_count = 0; not_switch_average = zeros(1,it); switch_average = zeros(1,it); for i=1:it r1 = randperm(n); gift_door = r1(1); r2 = randperm(n); chosen_door = r2(1); if chosen_door == gift_door not_switch_count = not_switch_count + 1; else switch_count = switch_count + 1; end not_switch_average(i) = not_switch_count / i; switch_average(i) = switch_count / i; figure(1);clf; colordef black set(gcf,'doublebuffer','on'); plot(1:i,not_switch_average(1:i),'r-','linewidth',2);hold on; plot(1:i,switch_average(1:i),'g-','linewidth',2); drawnow; end