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

trnegbin_pdf(n, Q, k)
% trnegbin_pdf.m - evaluates a Truncated Negative Binomial Probability Density.
%   See " Univariate Discrete Distributions", Johnson, Kotz, and Balakrishnan,
%   J. Wiley, p.233, 2005.
%
%    Created by:    J. Huntley,  10/11/2007
%

function [pdf] = trnegbin_pdf(n, Q, k)

%persistent coef PdQ

%if(isempty(coef))
    P = Q - 1;
    PdQ = P/Q;
    omPdQk = (1 - PdQ)^k;
    omQmk = (1 - Q^(-k));
    coef = omPdQk / omQmk;
%end

pdf = coef * binomial_coef(k+n-1,k-1) * PdQ^n;

return

Contact us