Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

 

generates random variates from over 870 univariate distributions

nsuccess_pdf(n, p, k, nn)
% nsuccess_pdf.m - evaluates the Number of Success Runs of length K (or longer) Probability Density.
%   See "Simple Expressions for Success Run Distributions in Bernoulli Trials",
%   M. Muselli, Genoa.
%
%  Created by Jim Huntley,  01/02/08
%

function [pdf] = nsuccess_pdf(n, p, k, nn)

mmax = fix((nn+1)/(k+1));
q = 1 - p;

summ = 0;
for m = n:mmax  
    bmn = (-1)^(m-n) * binomial_coef(m,n);
    sumy = 0;
    ymin = m; 
    ymax = nn - m*k + 1;
    for yy = ymin:ymax
        y = yy - 1;
        sumy = sumy + binomial_coef(y+1,m) * binomial_coef(nn-m*k,y) * ...
                      p^(nn-y) * q^y;
    end
    summ = summ + bmn * sumy;
end
pdf = summ;


return

Contact us