clear nmax=10; nhist=1000000; h=zeros(nhist,1); i=(1:nmax)'; up=2-1./i; for j=1:nhist if(rem(j,10000)==0) j end h(j)=mean(rand(nmax,1).*up); end [hi,l]=hist(h,100); dl=diff(l); dl=dl(1); m=mean(h); v=var(h); th=1/sqrt(2*pi*v)*exp(-(l-m).^2/2/v)*dl*length(h); pl=plot(l,hi,'b',l,th,'r--'); legend(pl,'histogram','Gaussian') title('Histogram and Gaussian for mean of 10 random variables') xlabel('x') ylabel('probability distribution') print -depsc comp_hist_gauss