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

sz_cdf(x, n)
% sz_cdf.m - compute Student's Z Cumulative Distribution Function.
%   See "Student's Z Distribution", http://mathworld.wolfram.com.               
%
%               Vector Form of CDF !!!
%
%  Created by:  Jim Huntley,  11/04/05.
%

function [cdf] = sz_cdf(x, n)

% NOTE:  To save time, use the following commented code to replace the eplicit CDF 
% code listed here. That is, numerically integrate the PDF instead of using the 
% explicit form of the CDF. Remember to change the solution type from "4" to "3" 
% in the Excel spreadsheet of distributions. 

% Integrate PDF to get CDF.
pdf = sz_pdf(x, n);
sx = size(x,2);
cdf(1:sx) = 0;
dx = x(2) - x(1);

for jx = 1:sx
    if(jx <= 2)
        cdf(jx) = trapz(pdf(1:jx)) * dx;
    elseif(jx > 2)
        cdf(jx) = simps(pdf(1:jx)) * dx;
    end
end

% Explict solution for CDF (slow).
%persistent coef

%if(isempty(coef))
%    coef = exp(gammaln(n/2) - (log(2) + log(sqrt(pi)) + gammaln((n+1)/2)));
%end

%d = coef * (abs(x))^(1-n) * hypergeom([(n-1)/2 n/2],(n+1)/2,-x^(-2));
%if(x <= 0)
%    cdf = d;
%end
%if(x > 0 )
%    cdf = 1 - d;
%end

return



Contact us