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

rutherford_pdf(n, c, p, nn)
% rutherford_pdf.m - evaluates a Rutherford Urn Probability denisity.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, p.526, 2005.  
%
%   Note sign error in text.
%
%   Created by  J. Huntley,  10/18/07.
%

function [pdf] = rutherford_pdf(n, c, p, nn)

%persistent coef

%Initializations.
%if(isempty(coef))
    coef = gammaln(p/c);
%end

% Evaluate PDF.
sumr = 0;
for jr = 1:n+1
    r = jr - 1;
    sumr = sumr + (-1)^r * binomial_coef(n,r) * (1-p-c*r)^nn;
end
pdf = exp(-coef + log(sumr) + gammaln(p/c + n) - gammaln(n+1));

return


    

Contact us