% % Written by: % -- % John L. Weatherwax 2008-02-20 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- % the discrete probability distribution: p = [ 0.15, 0.22, 0.33, 0.1, 0.2 ]; nSamps = 1e6; tsamps = disc_acc_rej( p, nSamps ); fprintf('empirical probabilities of each index= '); for ii=1:length(p) fprintf('%10.6f ',length(find(tsamps==ii))/nSamps); end fprintf('\n'); nSamps = 500; tsamps = disc_acc_rej( p, nSamps ); figure; [N,h] = hist( tsamps, 0:length(p) ); bar( h, N/nSamps ); axis( [ 0 6 0 0.5 ] ); grid on; saveas( gcf, 'prob_4_2', 'epsc' );