I would like to use MATLAB to visualize the Central Limit Theorem in action. I would like to use rand()
to produce 10 samples of uniform distribution U[0,1]
and compute their average, then save it to a matrix 'Mat'.
I would then use a histogram to visualize the convergence in distribution. How would you do this and normalize that histogram so it is a valid probability density (instead of just counting the frequency of occurrence)?
To generate the samples I am doing something like:
Mat = rand(N,sizeOfVector) > rand(1);
But I guess I am going to the wrong side.
To generate N
samples of length sizeOfVector
you start out with rand
as you suggested, and then continue as follows (calling the array average
instead of Mat
for readability):
samples = rand(N,sizeOfVector);
average = mean(samples,1);
binWidth = 3.49*std(average)*N^(-1/3)); %# Scott's rule for good bin width for normal data
nBins = ceil((max(average)-min(average))/binWidth);
[counts,x] = hist(average,nBins);
normalizedCounts = counts/sum(counts);
bar(x,normalizedCounts,1)