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

tpnorm_pdf(x, sigma1, sigma2, tsi)
% tpnorm_pdf.m - evaluates a Two-Piece normal Probability Density.
%   See "Continuous Univariate Distributions", v.1, Johnson, Kotz, &,
%   Balakrishnan, Wiley, 1995, p.173.
%
%   Vector form of PDF!!!
%
%  Created by Jim Huntley,  01/08/10
%

function [pdf] = tpnorm_pdf(x, sigma1, sigma2, tsi)

%persistent coef sigma1sq sigma2sq

%if(isempty(coef))
    coef = sqrt(2) / (sqrt(pi)*(sigma1+sigma2));
    sigma1sq = sigma1^2;
    sigma2sq = sigma2^2;
%end

for jx = 1:size(x,2)
    if(x(jx) <= tsi)
        pdf(jx) =  coef * exp(-0.5*(x(jx)-tsi)^2/sigma1sq); 
    elseif(x(jx) > tsi)
        pdf(jx) =  coef * exp(-0.5*(x(jx)-tsi)^2/sigma2sq);
    end
end

return

Contact us