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

strctasin_pdf(n, alpha, p)
% strctasin_pdf.m - evaluates a Strict Arcsine Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, p.250, 2005. 
%
%  Created by Jim Huntley,  10/08/07
%

function [pdf] = strctasin_pdf(n, alpha, p)

%persistent coef alphasq logp

%if(isempty(coef))
    coef = -alpha*asin(p);
    alphasq = alpha^2;
    logp = log(p);
%end

if(mod(n,2) == 0)
    z = n / 2;
    A = 1;
    for kk = 1:z
        k = kk - 1;
        A = A * (alphasq + 4*k^2);
    end
elseif(mod(n,2) == 1)
    z = (n-1) / 2;
    A = alpha;
    for kk = 1:z
        k = kk - 1;
        A = A * (alphasq + (2*k+1)^2);
    end
end
pdf = exp(coef + log(A) + n*logp - gammaln(n+1));

return


Contact us