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

gegen_pdf(n, rho, delta, l)
% gegen_pdf.m - evaluates a Gegenbauer Probability Density.
%   See "Continuous Univariate Distributions ", Johnson, Kotz, & Balakrishnan, 
%   Wiley, V. 1, p.500, 1995.
%
%  Created by Jim Huntley,  01/17/07
%

function [pdf] = gegen_pdf(n, rho, delta, l)


%persistent logxi logeta coef gaml 

% Initializations.
%if(isempty(logxi))
    xi = 1 / (1+rho+delta);
    logxi = log(xi);
    eta = rho * xi;
    logeta = log(eta);
    coef = (1 - xi - eta)^l;
    %gaml = gamma(l);
    gaml = gammaln(l);
%end

jlim = fix(n/2)+1;

% Calculate PDF.
sum = 0;
for jn = 1:jlim
    %sum = sum + gamma(n+l-jn+1) * xi^(n-2*jn+2) * eta^(jn-1)) - ...
    %      ((factorial(jn-1)) + gamma(n-2*jn+3) + gaml);
    sum = sum + exp(gammaln(n+l-jn+1) + (n-2*jn+2)*logxi + (jn-1)*logeta - ...
           (gammaln(jn) + gammaln(n-2*jn+3) + gaml));
end
pdf = coef * sum;

return

Contact us