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

partitioni8(n)
% partitioni8.m - calling program to compute integer partitions of n.
%
% Created by:  J. Huntley,  9/26/05, modified for int8 output, 03/25/09.
%
% Calls:  'i_partition_next2.m' - (Burkhardt) computes partions of n one at a time.
%
% Called by:  'crommelin_cdf.m', 'crommelin_pdf.m', & MANY others.
%
% Inputs:   n - integer to be partitioned.
%
% Outputs:  L - cell array of partition sets
%           cellmax - number of sets in the partition
%           a_new_hold - cell array of integers in each set
%           mult_new_hold - cell array of multiplicity of integers in each set 
%


function [L, callmax, a_new_hold, mult_new_hold] = partitioni8(n)

parts = [1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 ...
         1255 1575 1958 2436 3010 3718 4565 5604 6842 8349 10143 12310 14883 17977 ...
         21637 26015 31185 37338 44583 53174 63261 75175 89134 105558 124754 147273 ...
         173525 204226 239943 281589 329931 386155 451276 526823 614154 715220 ...
         831820 966467];
partsmax = size(parts,2);
more = false;
callmax = parts(min(n,partsmax));
npart = 0;
a = 0;
mult = 0;

for jc = 1:callmax
    
    [ npart_new, a_new, mult_new, more_new ] = i_partition_next2 ( n, npart, a, ...
                                                                   mult, more );

    npart = npart_new;
    a = a_new;
    mult = mult_new;
    more = true;
    
    startindx = 1;
    stopindx = 0;
    for js = 1:npart        
        stopindx = stopindx + mult_new(js);
        term(startindx:stopindx) = int8(a_new(js));
        startindx = stopindx + 1;
    end

    L{jc} = [term(1:stopindx)];
    a_new_hold{jc} = a_new;
    mult_new_hold{jc} = mult_new;
    clear term
    if (more_new <= 0)
        break
    end
    
end

if(callmax > partsmax)
    callmax = partsmax;
end

return
    

Contact us