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

crommelin_cdf(n, rho, D, nend, c, nq, q)
% crommelin_cdf.m - evaluates a Crommelin Cumulative Distribution.
%   See "A Simple Solution for the M/D/c Waiting Time Distribution",
%   G.J. Franx, U. Amsterdam, 16 November, 1998.
%
%  Created by Jim Huntley,  10/28/11.
%

function [cdf] = crommelin_cdf(n, rho, D, nend, c, nq, q)

%Initializations

sn = size(n,2);
lambda = rho * c / D;
llam = log(lambda);
kend = fix(nend+eps) / D;
for jq = 1:nq
    lQ(jq) = log(sum(q(1:jq)));
end

cdf(1:sn) = 1;
for jk = 1:kend
   
    nmin = (jk-1) * D;
    nmax = jk * D;
    for jn = nmin+1:nmax
       
        sumj = 0;
        for jj = 1:jk*c
          
            j = jj - 1;
            qndx = max(1,min(jk*c - j,nq));
            sumj = sumj + exp(j*llam + j*log(jk*D-n(jn)) + lQ(qndx) - gammaln(jj));
        end
        cdf(jn) = exp(-lambda*(jk*D-n(jn))) * sumj;
    end
end

return

Contact us