%% Gaussian Approximation to Poisson 

lambda=50;   %expected value

sigma=  sqrt(lambda);       %standard deviation
mu=     lambda;             %mean

%The Poisson proability mass function for k number of successes
P_k=inline('lambda^k*exp(-lambda)/gamma(k+1)','k','lambda')

%The Gaussian probability density function 
P_x=inline('1/sqrt(2*pi*sigma^2)*exp( -(x-mu).^2/(2*sigma^2))','x','mu','sigma')


%Calculate P(k,lambda) for a range of k values
clear PP
k_max=max(10,3*lambda);
k=(0:k_max);
for ii=1:length(k)
    PP(ii)=P_k(k(ii),lambda);
end

%Calculate P(x) for a range of x values
clear PG
dx=.5;
x_max=k_max;
x=(0:dx:x_max);
for ii=1:length(x)
    PG(ii)=P_x(x(ii),mu,sigma);
end

%Plot the probability distribution
figure
bar(k,PP,'r','linewidth',2)
hold on
plot(x,PG,'k','linewidth',3)
xlabel('x,k','fontsize',14)
ylabel('P','fontsize',14)
legend('Poisson PMF','Gaussian PDF')
s=sprintf('Poisson and Gaussian Distribution, \\lambda=%g',lambda)
title(s)





