Contents

%Generates Poisson variables
%input parameters:
%n, the number of variates to generate
%lambda, the Poisson parameter (which is the mean and variance)
%output: PoissonVariates.dat  (ascii, one variate per line)
%header lines are marked by "%"

Poisson Probability Density Function

$$P(k) = \frac{\exp(-\lambda)}{k!}$$

here $k=0,1,2,...$

    n=10000;
    lambda=1;
    outfile='PoissonVariates.dat';
    fid=fopen(outfile,'w');

    fprintf(fid,'%%Poisson variates\n');
    fprintf(fid,'%%lambda=%5.3f\n',lambda);


    kp=poissrnd(lambda,1,n);
    fprintf(fid,'%d\n',kp);
    fclose(fid);


    histogram(kp,15);


    kpmean=mean(kp);
    kprms=rms(kp);
    kpmed=median(kp);
    fprintf('mean: %f median: %f rms: %f\n',kpmean,kprms,kpmed);
mean: 0.987700 median: 1.408368 rms: 1.000000