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

hermite_pdf(n, alpha, bet)
% hermite_pdf.m - evaluates a Hermite Probability Density.
%   See "Dataplot Reference Manual, HERPDF, NIST, 7/7/4
%
%   NOTE: Patel's approximation for large n not working - many typos!!!
%
%  Created by Jim Huntley,  8/05/04
%

function [pdf] = hermite_pdf(n, alpha, bet)

p(1) = exp(-alpha*bet-0.5*alpha^2);
p(2) = alpha*bet*p(1);
nlim = 100;
if(n == 0)
    pdf = p(1);
elseif(n == 1)
    pdf = p(2);
elseif(n > 1 && n < nlim+1)
    for jn = 3:n+1
        p(jn) = (1/(jn-1))*(alpha*bet*p(jn-1) + alpha^2 * p(jn-2));
    end
    pdf = p(n+1);
elseif(n > nlim)
    A = alpha^2 / (8*bet);
    B = 4*n + 1;
    C = 0.5 * (4*n+3);
    if(mod(n,2) == 0)
        theta = cosh(sqrt(A)*sqrt(A+B) + B*log((1+A/B)^0.25+sqrt(A/B)));
        pdf = exp(-(alpha+bet+A)) * bet^n * theta / (sqrt(1+A/B) * gamma(n+1));
    elseif(mod(n,2) == 1)
        theta = sinh(sqrt(A)*sqrt(A+C) + C*log(sqrt(1+A/C)+sqrt(A/C)));
        pdf = exp(-(alpha+bet+A)) * bet^n *sqrt(2*bet) * theta * (1+A/C)^(-0.25) / sqrt(gamma(n+1)*C);
    end
end

return

Contact us