% Rolling of a fair die
% Proportion of 6's in N rolls. N rolls repeated M times
% Plot: Histogram of the proportion with
% superimposed theoretical probability of 1/6.
clear all
close all
disp('Proportion of Sixes')
lw = 2;
set(0, 'DefaultAxesFontSize', 16);
fs = 15;
msize = 10;
%
M=1000; %M is number of different simulations
N=1000; %N is number of rolls in a single simulation
psixs =[]; %Keep here the proportion of 6's.
for i = 1:M
nsix=0;
for j= 1:N
nsix = nsix + (rand<1/6);
end
psix = nsix/N;
psixs = [psixs psix]; %collect all approximate probabilities
end
hist(psixs, 20)
hold on
plot([1/6 1/6],[0 N/5],'r-', 'linewidth',4)
hold off
mean(psixs)