% Negative Exponential Distribution Analysis
% A.A. Trani (October 1, 1998)

% Function calls: 
% negexs.m - second moment of the Chi-square dist.
% negexf.m - first moment of the Chi-square dist.

global BETA

% Define an array for the random variable x (say between 0 and 10)

x=0:.1:10;

% Define the parameter of the distribution (mean)

BETA = 5;


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

fx = 1/BETA*exp(-x/BETA);

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

Pn=quad8('negexp',5,200);

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

mean_negexp = quad8('negexpf',0,100);
var_negexp = quad8('negexps',0,100);

  disp(' ')
  disp([blanks(5),'First moment of Neg. Exp. PDF : '])
  disp(' ')
  disp([blanks(5),'     P(x>0)=',num2str(mean_negexp)])
  disp(' ')
  



