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

pear7lapld_cdf(x, a)
% pear7lapld_cdf.m - evaluates a Pearson 7 Laplace Difference Cumulative Distribution.
%   See "On the Product and Ratio of Pearson Type VII and Laplace Random Variables", 
%   S. Nadrajah and S,. Kotz, Austrian J. of Stat., Vol.34, No.1, p.11, 2005.
%
%  Created by Jim Huntley,  04/09/09
%
%   Vector form of CDF!!!
%

function [cdf] = pear7lapld_cdf(x, a)

%persistent rta moda2 dy y expmy

%if(isempty(rta))
    rta = a;
    moda2 = mod(a,2);
    if(moda2 == 1)
        rta = sqrt(a);
    end
    ny = 1000;
    ymin = 0;
    ymax = x(end);
    dy = (ymax-ymin) / (ny-1);
    y = ymin:dy:ymax;
    expmy = exp(-y);
%end    

for jx = 1:size(x,2)
    sumk = 0;
    alim = a/2;
    if(moda2 == 1)
        alim = (a-1) / 2;
    end
    for jk = 1:alim
        if(moda2 == 1)
            kernJ = y .* expmy ./ (y.^2.*x(jx)^2+a).^jk;
            J = simps(kernJ) * dy;
            sumk = sumk + a^jk * beta(jk,0.5) * J;
        else
            kernJ = y .* expmy ./ (y.^2.*x(jx)^2+a).^(jk-0.5);
            J = simps(kernJ) * dy;
            sumk = sumk + a^jk * beta(jk-0.5,0.5) * J;
        end
    end
    I = 0;
    if(moda2 == 1)
        kernI = atan(x(jx).*y./rta) .* expmy;
        I = 2 * simps(kernI) * dy / pi;
    end
    cdf(jx) = I + x(jx) * sumk / (pi * rta);
end

return

Contact us