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

cantor_cdf(x, maxdigits)
%cantor_cdf.m - generate Cantor Cumulative Distribution Function
%   See http://en.wikipedia.org/wiki/Cantor_function.
%
%   Calls:  'dec2basen.m'
%
%   Vector Form of CDF !!!
%
%   Author - J.M. Huntley
%   Date - 05/25/2011
%

function[cdf] = cantor_cdf(x, maxdigits)

base = 3;
%Convert to base 3
digits = dec2basen(x,base,maxdigits);
sx = size(x,2);
for jx = 1:sx    
    %Replace all digits beyond the first '1' with '0's.
    for jd = 1:maxdigits
        if(digits(jx,jd) == 1)
            digits(jx,jd+1:end) = 0;
            break
        end
    end
    %Replace all '2's with '1's.
    for jd = 1:maxdigits
        if(digits(jx,jd) == 2)
            digits(jx,jd) = 1;
        end
    end
    %Convert from array of binary values to string array to a decimal 
    %number and normalize.
    cdf(jx) = bin2dec(int2str(digits(jx,1:end))) ./ 32767;
end

return



Contact us