% File: http://web.mit.edu/8.13/matlab/Examples/simpoisson.m % Date: 2008-June-13 % Author: Scott Sewell %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This script demonstrates how to generate a sample population of % Poisson distributed events and to compare this sample distribution % with the parent probability distribution function from % which they were drawn. Try simpoisson(1.67,1000) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [x,y] = simpoisson(mu,trials) xmax=mu+8*sqrt(mu); x=[0:xmax]; sample=poissrnd(mu,1,trials); x1=[0:xmax]; parent=poisspdf(x1,mu)*trials; y=hist(sample,x); bar(x,y,.8,'g'); hold on; plot(x1,parent,'ko:') legend('Sample Population','Parent Distribution'); title(['Poisson Distributions - \mu=',num2str(mu),' Total Trials=',int2str(trials)]); xlabel('Value') ylabel('Number of Trials');