% HISTPROBTOTAL % Lecture 6B demo: Probability of obtaining % a "nearly" uniform histogram, that is, % all bars within given tolerance. % % Default parameters: % k=10 categories (bars) % n=100 points sampled % % Tolerance is how much the bars are allowed to differ from % the expected height, which is n/k. % function p = histprobtotal(tolerance, n, k) if nargin<2, n=100; end if nargin<3, k=10; end % This is a laborious method, but the computer does it. % Consider, one by one, each possible collection of bar heights % such that the heights are within the tolerance. p = 0; minx = ceil(n/k - tolerance); maxx = floor(n/k + tolerance); Y = maketerms(n, k, minx, maxx); fprintf('we find %d different histograms within tolerance\n', size(Y,1)); for i=1:size(Y,1) p = p + histprob(Y(i,:)); end end