%% Exercise 1 -- Getting started with MATLAB and distributions

% In this exercise, lines not preceded by the '%' symbol are Matlab
% commands that can be executed either from the command line or from an
% m-file.

% Step 1. Generate random sample of 100 points from Normal distribution

N=100; 

% This command generates a variable 'N' in the Workspace. 
% It is always a good practice to store parameters in variables.
% Semicolumn after the command supresses the output of the result to
% screen. (Depete the semicolumn and see the effect for yourself.)

% Now, define the mean and standard deviation for the Normal distribution^

mu = 5;
sig = 2;

% Generate a set of numbers drawn from the Normal distribution. For the
% description of the command 'normrnd', see Matlab Help. This command is
% part of the Statistics toolbox. For an alternative algorythm, search Help
% for the 'randn' command.

X = normrnd(mu,sig,N,1);

% The variable X should now contain an array consisting of 100 numbers.
% Click on this variable in the Workspace and check that it is indeed so.

% Bin these numbers into a histogram.

hist (X,10);

% The last number is the number of bins. Experiment by changing this
% number.
% The same histogram can be obtained by clicking on X in the Workspace, 
% selecting the first column and selecting the histogram icon in the
% toolbar. 


% Step 2. Compute mean and variance from your sample distribution.

mean(X)
std(X)

% I wanted to see output on screen, so there is no semicolumn after the
% command.

% Repeat the exercise for N=1000 and N=10.




% Step 3. Explore the distribution fitting tool in the Statistics toolbox. 
% Start -> Toolboxes -> Statistics ->dfittool.

% Select the variable X as data and fit Normal distribution to the dataset.
% Compare the values of mean vand variance with values that you obtained
% earlier. Play with the bin sizes (in the Data... menu) and see if bin
% sizes affect the result. Why?



