This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/code/diehistograms.m

25 lines
514 B
Matlab

% dependence of histogram on number of rolls:
nrolls = [20, 100, 1000];
for i = [1:length(nrolls)]
d = rollthedie(nrolls(i));
% plain hist:
%hist(d)
% force 6 bins:
%hist(d, 6)
% set the right bin centers:
bins = 1:6;
%hist(d, bins)
% normalize histogram and compare to expectation:
plot([0 7], [1/6 1/6], '-r', 'linewidth', 10)
[h, b] = hist(d, bins);
h = h/sum(h) % normalization
hold on
bar(b, h, 'facecolor', 'b')
hold off
title(sprintf('N=%d', length(d)))
pause(2.0)
end