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

logn_pdf(x,mu,sigma)
function y = logn_pdf(x,mu,sigma)
%LOG_NPDF Lognormal probability density function (pdf).
%   Y = LOGN_PDF(X,MU,SIGMA) Returns the lognormal pdf at the values
%   in X. The mean and standard deviation of log(Y) are MU and SIGMA.
%
%   The size of Y is the common size of the input arguments. A scalar input  
%   functions as a constant matrix of the same size as the other inputs.     
%
%   Default values for MU and SIGMA are 0 and 1 respectively.

%   Reference:
%      [1]  Mood, Alexander M., Graybill, Franklin A. and Boes, Duane C.,
%      "Introduction to the Theory of Statistics, Third Edition", McGraw Hill
%      1974 p. 540-541.

%   Copyright 1993-2000 The MathWorks, Inc. 
%   $Revision: 2.11 $  $Date: 2000/05/26 18:53:00 $

if nargin < 3, 
    sigma = 1;
end

if nargin < 2;
    mu = 0;
end

if nargin < 1, 
    error('Requires at least one input argument.');
end

[errorcode x mu sigma] = distchck(3,x,mu,sigma);

if errorcode > 0
    error('Requires non-scalar arguments to match in size.');
end

%   Initialize Y to zero.
y = zeros(size(x));

k = find(sigma > 0 & x > 0);
if any(k)
    xn = (log(x(k)) - mu(k)) ./ sigma(k);
    y(k) = exp(-0.5 * xn .^2) ./ (x(k) .* sqrt(2*pi) .* sigma(k));
end

% Return NaN if SIGMA is negative or zero.
y(sigma <= 0 | x < 0) = NaN;

Contact us