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

gensech_pdf(x, rho, theta)
% gensech_pdf.m - evaluates a Generalized Hyperbolic Secant Probability Density.
%   See "Continuous Univariate distributions", Johnson, Kotz, & Balakrishnan,
%   Wiley, V. 2, p. 148, 1995.
%
%  Created by Jim Huntley,  02/07/07
%
%   Vector Form of PDF !!!
%

function [pdf] = gensech_pdf(x, rho, theta)

% Initializations.
sx = size(x,2);
arg = 0.5 * pi / theta;
pdf(1:sx) = 0;
denom = 0.25 / theta^2;

% Calculate PDF for 'rho' even.
if(mod(rho,2) == 0) 
    n = rho / 2;
    %coef = 4^(n-1) / (theta^2 * factorial(2*n-1));
    coef = (n-1)*log(4) - (2*log(theta) + gammaln(2*n));
    for jx = 1:sx
        prod = 1;
        for jj = 1:n-1
            prod = prod * (jj^2 + denom * x(jx)^2);
        end
        %pdf(jx) = coef * x(jx) * prod / sinh(arg*x(jx));
        pdf(jx) = exp(coef + log(x(jx)) + log(prod) - log(sinh(arg*x(jx))));
    end
% Calculate PDF for 'rho' odd.
elseif(mod(rho,2) == 1)
    n = (rho-1) / 2;
    %coef = 2^(2*n) / (theta * factorial(2*n)); 
    coef = 2*n*log(2) - (log(theta) + gammaln(2*n+1));
    for jx = 1:sx
        prod = 1;
        for jj = 1:n
            prod = prod * ((jj-0.5)^2 + denom * x(jx)^2);
        end
       %pdf(jx) = coef * prod / cosh(arg*x(jx));
       pdf(jx) = exp(coef + log(prod) - log(cosh(arg*x(jx))));
    end
end

return

Contact us