% BRIEF RECAP of October 22nd, 1998 NEEP271 lecture
% written by Fabian Waleffe 98/10/22
%
% we demo'd some linear curve fits using Matlab's powerful "\"
%
% Then we alked about DATA ANALYSIS:
%                     =============
%  MEAN, MEDIAN, VARIANCE, STANDARD DEVIATION (STD), MAX, MIN, SORT
%
%  what these are and how Matlab calculates them (see "help datafun")
%
% We also talked about RANDOM VARIABLES:
%                      ================
%  PROBABILITY DENSITY (or DISTRIBUTION) FUNCTION ("pdf" for short)
%
%  probability for x to be in [x, x+dx] = p(x) dx
%  probability for x to be in [a     b] = Integral from a to b of p(x) dx
%
%  UNIFORM DISTRIBUTION: p(x) =1 for x in [0,1], 0 otherwise
%  GAUSSIAN (NORMAL)   : p(x) =1/sqrt(2 pi) exp(-x^2/2)   (mean 0, std 1)
%
% we illustrated all of this using the grades from exam 1.
%

% EXAM GRADES

ex=[24 24 31 32 32 34 34 41 42 44 44 44 45 45 46 51 51 53 53 53 54 56 58 60 60 61 62 66 67 69 73 74]';

max(ex)
min(ex)
mean(ex)
median(ex)
std(ex)

plot(ex,'o')

hist(ex)      % histogram with 10 bins (default)

hist(ex,100)  % histogram with 100 bins 

% RANDOM DISTRIBUTIONS:

x=rand(1000,1); hist(x)       % UNIFORM  (REPEAT SEVERAL TIMES)

x=randn(1000,1); hist(x,50)  % GAUSSIAN (REPEAT SEVERAL TIMES)

% COMPARE EXAM TO RANDOM NUMBERS

xu=100*rand(length(ex),1);    %Uniform in [0,100], as many numbers as exam scores.
xu=sort(xu) ;                 %sort in increasing order

plot(ex,'o'), hold on, plot(xu,'*')       % compare exams to uniform distribution
xu=100*rand(length(ex),1); xu=sort(xu) ;  % another uniform realization
plot(xu,'rx')

xn=50 + std(ex)*randn(length(ex),1);    %Gaussian with mean 50 and std=std(ex)
xn=sort(xn);                 

plot(ex,'o'), hold on, plot(xn,'g^')    % compare exams to uniform distribution

xn=50 + std(ex)*randn(length(ex),1); xn=sort(xn);  % another realization
plot(xn,'cs')

xn=50 + std(ex)*randn(length(ex),1); xn=sort(xn);  % yet another realization
plot(xn,'md')

hold off            % release plot

disp('we do not have much data, but ')
disp('grades do look more like random Gaussian than random uniform')
