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

bates_pdf(x, nn)
% bates_pdf.m - evaluates a Bates Probability Density.
%   See "Continuous Univariate Distributions", Johnson, Kotz, and
%   Balakrishnan, V2, J. Wiley, , p.297, 1996. 
%
%  Created by Jim Huntley,  10/27/06
%

function [pdf] = bates_pdf(x, nn)

%persistent lnn gamnn lmin nm1

%if(isempty(lnn))
    lmin = 1e-8;
    lnn = nn*log(max(nn,lmin));
    gamnn = gammaln(nn);
    nm1 = nn - 1;
%end

sum1 = 0;
jlim = fix(x * nn);

for jj = 1:jlim+1
    sum1 = sum1 + (-1)^(jj-1) * binomial_coef(nn,jj-1) * (x-(jj-1)/nn)^nm1;
end

%pdf = nn^nn * sum1 / gamma(nn);
pdf = exp(lnn + log(max(sum1,lmin)) - gamnn);

return

Contact us