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

betawarn_pdf(x, b, m, n, nu1, nu2)
% betawarn_pdf.m - evaluates a Beta Warning Time Probability Density.
%   See "Continuous Univariate Distributions", Johnson, Kotz, and
%   Balakrishnan, V2, J. Wiley, , p.350, 1996. 
%
%               Vector Form of PDF !!!
%
%  Created by Jim Huntley,  11/17/06
%

function [pdf] = betawarn_pdf(x, b, m, n, nu1, nu2)

%persistent nurat coef odb pow0 pow1 nm1 mm1 ny ymax

% Initializations.
%if(isempty(coef))
    nurat = nu1 / nu2;
    coef = nurat^(0.5*nu1) / (b * beta(m,n) * beta(0.5*nu1,0.5*nu2));
    odb = 1 / b;
    pow0 = 0.5*nu1/b - m - n;
    pow1 = 0.5 * (nu1+nu2);
    nm1 = n - 1;
    mm1 = m - 1;
    yscale = 5;
    ny = 1000 * yscale;
    ymax = yscale * x(end);
%end

% Compute PDF.
for jx = 1:size(x,2)
    ymin = x(jx);
    dy = (ymax-ymin) / (ny-1);
    y = ymin:dy:ymax;
    kern = y.^pow0 .* (y-x(jx)).^nm1 ./ (1+nurat.*y.^odb).^pow1;
    yint = simps(kern) * dy;
    pdf(jx) = coef * x(jx)^mm1 * yint;
end

return

Contact us