Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

James Huntley (view profile)

 

generates random variates from over 870 univariate distributions

binomhyp_pdf(n, p, N1, Np, N2)
% binomhyp_pdf.m - evaluates a Binomial Hypergeometric Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, p.300, 2005. 
%
%  Created by Jim Huntley,  11/21/06
%

function [pdf] = binomhyp_pdf(n, p, N1, Np, N2)

% Initializations.
sum1 = 0;
jmin = n + 1;
jmax = min(N1,Np) + 1;
coef = 1 / binomial_coef(N2,N1);

for jn = jmin:jmax
    sum1 = sum1 + binomial_coef(Np,jn-1) * binomial_coef(N2-Np,N1-jn+1) * ...
                binomial_coef(jn-1,n) * p^n * (1-p)^(jn-n-1);
end
pdf = coef * sum1;

return


Contact us