Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

 

generates random variates from over 870 univariate distributions

...
% stable_rnd.m - generates 'nsamples' of a Stable random variable.
% from "http://www.xplore-stat.de/ebooks/scripts/csa/html/node235.html"
%
%   Created by: J. Huntley,  09/25/06
%

function [xhold,fhold,ghold,jhold,xsort,fsort,gsort,chold,isint] = ...
          stable_rnd(userin,p_value,nsamples)

alpha = p_value(1);
sigma = p_value(2);
bet = p_value(3);
mu = p_value(4);
zeta = -bet * tan(0.5*pi*alpha);
userin.distrib = 'exp'; 
userin.ftype = 4;
userin.p_value = [1];
iseed = userin.iseed;
[xhold,fhold,ghold,jhold,xsort,fsort,gsort,chold,isint] =  gen_distrib2(userin,iseed);
W = xhold;
U = (rand(1,nsamples)-0.5).*pi;
if(alpha == 1)
    zi = 0.5 * pi;
    X = ((zi+bet.*U).*tan(U) - bet.*log(zi.*W.*cos(U)./(zi+bet.*U))) ./ zi;
    xhold = sigma.*X + 2.*bet.*sigma.*log(sigma)./pi + mu;
elseif(alpha ~= 1)
    zi = atan(-zeta) / alpha;
    X = (1+zeta^2)^(0.5/alpha) .* sin(alpha.*(U+zi)) .* (cos(U-alpha.*(U+zi))./W).^((1-alpha)/alpha) ...
        ./ (cos(U)).^(1/alpha);
    xhold = sigma.*X + mu;
end
      
return

Contact us