% % Session 1 (script session1.m) % clear T=rand(1000,1000); % % you can put your comments here... % for i=1:10 %...or actually anywhere a(i,:)=mean(T(1:i*100,:)); end % % % for i=1:10 s2(i,:)=var(T(1:i*100,:)); end % % % figure % % Figure 1 % hist(a(1,:),15) figure % % Figure 2 % hist(a(2,:),15) figure(1) xlabel('a') ylabel('number of observations') title('Histogram of a sample mean (N=100)') figure(2) xlabel('a') ylabel('number of observations') title('Histogram of a sample mean (N=200)') set(gca,'xlim',[0.4 0.6]) figure(1) set(gca,'xlim',[0.4 0.6]) % % % mina=min(min(a)); maxa=max(max(a)); da=(maxa-mina)/15; edgesa=[mina:da:maxa]; % % % h1=histc(a(1,:),edgesa); whos h1 size(h1,1) size(h1,2) h1=h1/(size(h1,2)*mean(h1,2)); mean(h1)*size(h1,2) % % % figure % % Figure 3 % plot(edgesa,h1) % h10=histc(a(10,:),edgesa); h10=h10/(size(h10,2)*mean(h10,2)); hold on plot(edgesa,h10,'r') legend('N=100','N=1000') xlabel('a') ylabel('p(a)') title('Estimated PDF of an average of a sample of size N drawn from a uniform distribution on [0,1]') grid on % % % mean(a') var(a') N=[100:100:1000]; % % % figure % % Figure 4 % plot(N,1./var(a'),'x') hold on plot(N,12*N,'r') legend('numerical result','theoretical prediction') xlabel('N') ylabel('Var{N}') title('Numerical and theoretical estimates of the sample-mean\prime s dispersion as a function of a sample size N') grid on % % End of script %