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

rectline_pdf(x, w, h)
% rectline_pdf.m - evaluates a Rectangle-Line Probability Density.
%   See "On the Probability Distribution of the Minimal Number of Hops
%   Between any Pair of Nodes in a Bounded Wireless Ad-Hoc Network Subject
%   to Fading", S. Mukherjee and D. Avidor, Lucent.
%
%   Vector Form of PDF !!!
%
%  Created by Jim Huntley,  7/26/06
%

function [pdf] = rectline_pdf(x, w, h)

coef = 4 / (h*w);
od2hw = 1 / (2*h*w);
R = sqrt(w^2 + h^2);
wsq = w^2;
hsq = h^2;
sx = size(x,2);

for jx = 1:sx
    if(x(jx) >= 0 && x(jx) < w)
        pdf(jx) = coef * x(jx)*(0.5*pi - x(jx)*(1/w + 1/h) + od2hw*x(jx)^2);
    elseif(x(jx) >= w && x(jx) < h)
        pdf(jx) = coef * x(jx)*(sqrt((x(jx)/w)^2 - 1) - (x(jx)/w+0.5*w/h) ...
                                + asin(w/x(jx)));
    elseif(x(jx) >= h && x(jx) <= R)
        pdf(jx) = coef * x(jx)*(sqrt((x(jx)/w)^2 - 1) + sqrt((x(jx)/h)^2 - 1) ...
                         - od2hw*(x(jx)^2+hsq+wsq) + asin(w/x(jx)) - acos(h/x(jx)));
    end
end 

return

Contact us