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

dtrbinom_pdf(n, nn, p, r1, r2)
% dtrbinom_pdf.m - evaluates a Doubly Truncated Binomial Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp & Kotz,
%   J. Wiley, p.137, 2005. 
%
%  Created by Jim Huntley,  12/20/06
%

function [pdf] = dtrbinom_pdf(n, nn, p, r1, r2)

q = 1 - p;
coef = binomial_coef(nn,n) * p^n * q^(nn-n);

sum1 = 0;
for jn = r1:nn-r2
    sum1 = sum1 + binomial_coef(nn,jn) * p^jn * q^(nn-jn);
end
pdf = coef / sum1;

return


Contact us