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_cdf(x, nn)
% bates_cdf.m - evaluates a Bates Cumulative Distribuiton.
%   See "Continuous Univariate Distributions", Johnson, Kotz, and
%   Balakrishnan, V2, J. Wiley, , p.297, 1996. 
%
%  Created by Jim Huntley,  10/27/06
%

function [cdf] = bates_cdf(x, nn)

%persistent lnn gamnn lmin

%if(isempty(lnn))
    lmin = 1e-8;
    lnn = (nn-1)*log(max(nn,lmin));
    gamnn = gammaln(nn);
%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)^nn;
end

%cdf = nn^(nn-1) * sum1 / factorial(nn-1);
cdf = exp(lnn + log(max(sum1,lmin)) - gamnn);

return

Contact us