% Normal Distribution Analysis
% A.A. Trani (October 10, 1998)

% Function calls: 

global MU SIGMA

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

MU = 65;
SIGMA = 15;

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

npoints = 100;
parameter = 3.5;
low = MU - parameter*SIGMA;
high = MU + parameter* SIGMA;
interval = (high - low) / npoints;

% Define random variable x

x=low:interval:high;


% Define the function of the random variable x (PDF function)

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 -infinity to infinity
% Change the values of the last two arguments if you 
% want another range of values

Pn=quad8('normal',-100,300);

  disp(' ')
  disp([blanks(5),'Area under the Normal Distribution : '])
  disp(' ')
  disp([blanks(5),'     P(x>0)=',num2str(Pn)])
  disp(' ')
  
% Compute the first and second moments of the distribution
%
% The first moment is the mean of the distribution
% the second moment is the variance

mean_normal = quad8('normalf',low-parameter*SIGMA,high+parameter*SIGMA);
var_normal = quad8('normals',low-parameter*SIGMA,high+parameter*SIGMA);

  disp(' ')
  disp([blanks(5),'First moment of Normal PDF : '])
  disp(' ')
  disp([blanks(5),'     P(x>0)=',num2str(mean_normal)])
  disp(' ')
  



