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

truncig_pdf(x, lambda, mu, x1, x2)
% truncig_pdf.m - evaluates a Truncated Inverse Gaussian Probability Density.
%   See " Continuous Univariate Distributions", Johnson, Kotz and Balakrishnan,
%   J. Wiley, v.1, p.277, 1995.
%
%   Vector form of PDF!!!
%
%  Created by Jim Huntley,  10/09/07
%
%   Calls:  'kern.m' (included), 'simps.m'
%

function [pdf] = truncig_pdf(x, lambda, mu, x1, x2)

%persistent coef dx

%if(isempty(coef))
    coef = 0.5 * lambda / mu^2;
    nx = 1000;
    dx = (x2-x1) / (nx-1);
%end

K = kern(x,coef,lambda);
sx = size(x,2);
if(sx < 3)
    K = 1 / (trapz(K) * dx);
elseif(sx >= 3)
    K = 1 / (simps(K) * dx);
end
    
pdf = K .* exp(-coef.*x - 0.5.*lambda./x) .* x.^(-1.5);

return

function [K] = kern(x,coef,lambda)

K = exp(-coef.*x-0.5.*lambda./x) .* x.^(-1.5);

return

Contact us