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

dblncf_pdf(x, nu1, nu2, lambda1, lambda2)
% dblncf_pdf.m - evaluatess a Doubly Non-Central F Probability Density.
%   See "Continuous Univariate Distributions", Johnson, Kotz, & Balakrishnan,
%   J. Wiley, v.1, p.499, 1994. 
%
%  Created by Jim Huntley,  12/20/06
%

function [pdf] = dblncf_pdf(x, nu1, nu2, lambda1, lambda2)

%persistent coef jlim klim ratioj ratiok exp1 exp2 B

% Initializations.
%if(isempty(coef))
    coef = exp(-0.5*(lambda1+lambda2));
    jlim = 20;
    klim = 20;
    for jj = 1:jlim
        facj = gammaln(jj);
        c1 = (0.5.*lambda1).^(jj-1);
        exp1(jj) = 0.5*nu1+jj-2;
        ratioj(jj) = exp(log(c1) - facj);
    end
    for kk = 1:klim
        fack = gammaln(kk);
        c2 = (0.5.*lambda2).^(kk-1);
        ratiok(kk) = exp(log(c2) - fack);
        for jj = 1:jlim
            exp2(jj,kk) = -0.5*(nu1+nu2)-jj-kk+2;
            B(jj,kk) = beta(0.5*nu1+jj-1,0.5*nu2+kk-1);
        end
    end   
%end

% Calculate PDF.
sum = 0;
opx = 1 + x;
for jj = 1:jlim
    for kk = 1:klim
        sum = sum + ratioj(jj) * ratiok(kk) * x^exp1(jj) * opx^exp2(jj,kk) / B(jj,kk);    
    end
end
    
pdf = coef * sum;
    
return

Contact us