% File: http://web.mit.edu/8.13/matlab/Examples/simpoisson.m % Date: 2008-June-13 % Author: Scott Sewell %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This script demonstrates how to generate and % compare sample populations from the Parent PDF's from % which they are 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('Sample and Parent Distributions - POISSON - \mu=',num2str(mu)); xlabel('Value') ylabel('Number of Samples (of 1000 trials)');