% Normal Distribution Analysis
% A.A. Trani (October 10, 2006)
%
% Purpose: shows a normally distributed random variable
% integrates numerically the a normal distribution between two
% intervals a and b

global mu sigma

% Define the parameter of the distribution (MU) and standard deviation (SIGMA)

mu = 65;
sigma = 10;

% Define upper and lower bounds to get a nice plot of the Gaussian PDF

npoints = 100;
parameter = 3.5;                    % 3.5 standard deviations from mean
low = mu - parameter*sigma;         % low value to make a plot
high = mu + parameter* sigma;       % high value to make a plot
interval = (high - low) / npoints;  % interval between data points

% Define random variable x

x=low:interval:high;


% Define the function of the random variable x (PDF function)
% cehck your statistics book in case you forgot the PDF of a
% normal distribution

fx = 1/(sigma * sqrt(2*pi)) * exp(-1/2 * ((x-mu)/sigma).^2 );

% Plot the random variable x versus the PDF function

plot(x,fx)
xlabel('Random variable - x')
ylabel('f(x)')
grid

% Compute area under the curve f(x) from a to b
% Change the values of the last two arguments if you 
% want another range of values

a= 70;
b=100;

% calculate the area under Gaussian curve between a and b

Pn=quad('normal',a,b);

  disp(' ')
  disp([blanks(5),'Area under the Normal Distribution : '])
  disp(' ')
  disp([blanks(5),'     P(a<x<b)= ',num2str(Pn)])
  disp(' ')
  



