% Unit 4 (MATLAB Course @ UAM)
% (c) Alexander Knebe

%========================================
% histograms & probability distributions
%========================================
clear all, close all, clc 

% simply plot histograms for the distribution of values returned by randn() and rand()
figure(1)
N = 1000000;
subplot(2,1,1), hist(randn(N,1),N/10000), xlabel('x'),ylabel('P(x)'),title('distribution of randn() values')
subplot(2,1,2), hist(rand(N,1), N/10000), xlabel('x'),ylabel('P(x)'),title('distribution of rand() values')

% normalise histograms to obtain probability distribution for randn()
figure(2)
[p,x] = hist(randn(1000000,1),100);
p     = normalise(p,x);
plot(x,p), hold on
[p,x] = hist(randn(100000,1),100);
p     = normalise(p,x);
plot(x,p,'r')
[p,x] = hist(randn(10000,1),100);
p     = normalise(p,x);
plot(x,p,'g')
[p,x] = hist(randn(10000,1),50);
p     = normalise(p,x);
plot(x,p,'g--')
legend('Nbins=100, N=1000000','Nbins=100, N=100000','Nbins=100, N=10000','Nbins=50,   N=10000')
xlim([-3.5,3.5])
ylim([0,0.55])



