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

gandh_cdf(xv,p_value)
% gandh_cdf.m - G and H Cumulative Distribution.
%               "Dataplot Reference Manual", Vol. 1, Aux, 7/7/04.
%
%   created by:  J. Huntley,  10/25/06.
%
%   Calls:    'gaus1_ppf.m'.
%
%   Vector Form of CDF.
%

function [cdf,fhold] = gandh_cdf(xv,p_value)

% Initializations.
g = p_value(3);
h = p_value(4);
rand('state',0);
nsamples = size(xv,2);
ppf(1:nsamples) = 0;

% Evaluate PPF for evenly-spaced CDF values on [0,1].
xhold = rand(nsamples,1);
for js = 1:nsamples
    urd1 = xhold(js);
    [gppf,xcdf] = gaus1_ppf(urd1,p_value);        % single valued Gaussian PPF.
    ppf(js) = gppf;
end
fhold = (exp(g.*ppf)-1) .* exp(0.5.*h.*(ppf).^2)./g;
fmin = min(fhold);
fmax = max(fhold);

% Sort "range" values of PPF into "domain" order.
[xsort, index] = sort(xhold);
fsort = fhold(index);

% Interpolate CDF values to uniform spacing, xi.
xi = fmin:(fmax-fmin)/(nsamples-1):fmax;
cdf = interp1(fsort,xsort,xi,'linear');

return

Contact us