% ----------------------------------
% central_limit.m
% Central Limit Theorem
% ----------------------------------
clear all;close all;
N=12;n=100000;nh=1000;
xx= linspace(-10,10,nh);
y=rand(n,N);
x=sum(y,2);
mu = sum(x)/n;
s = sqrt(sum((x-mu).^2))/sqrt(n);
x=(x-mu)/s;
h=xx(2)-xx(1);
his=hist(x,xx);
f = @(x) 1/(sqrt(2*pi))*exp(-x.^2/2);
%sum(f(xx))*h
subplot(2,1,1)
plot(xx,f(xx),'b-',xx,his/sum(his)/h,'r-');
subplot(2,1,2)
semilogy(xx,f(xx),'b-',xx,his/sum(his)/h,'r-');


