% 1) Generate data of a one-dimensional Gaussian distribution, 
% 2) Plot a normalized histogram estimate of the distribution,
% 3) Plot the true density.

clc
mean = 2; var = 5; nsamp = 3000;
xmin = -10; xmax = 10; nbins = 30;
disp('(Univariate) Gaussian sampling whose mean is')
dstring = [num2str(mean), ' and variance ', num2str(var), '.  ', ...
    num2str(nsamp), '=length.'];
disp(dstring);
x = mean + sqrt(var)*randn(nsamp, 1);
f = figure;
histpd(x, xmin, xmax, nbins);
hold on;
axis([xmin xmax 0 0.2]);
plotvals = linspace(xmin, xmax, 200)';
probs = gauss(mean, var, plotvals);
plot(plotvals, probs, 'r');
xlabel('X')
ylabel('Density')
title('Gaussian Distribution') 


% "Complex and Chaotic Nonlinear Dynamics. 
% Advances in Economics and Finance, 
% Mathematics and Statistics" 
% T.Vialar, Springer 2009.
% Copyright(c) 