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

geometric_pdf(x,p)
function y = geometric_pdf(x,p)
%GEOMETRIC_PDF Geometric probability density function (pdf).
%   Y = GEOMETRIC_PDF(X,P) returns the geometric pdf with probability, P, 
%   at the values in X.
%
%   The size of Y is the common size of X and P. A scalar input   
%   functions as a constant matrix of the same size as the other input.    

%   References:
%      [1]  M. Abramowitz and I. A. Stegun, "Handbook of Mathematical
%      Functions", Government Printing Office, 1964, 26.1.24.

%   Copyright 1993-2000 The MathWorks, Inc. 
%   $Revision: 2.8 $  $Date: 2000/05/26 18:52:54 $

if nargin < 2, 
   error('Requires two input arguments.'); 
end

[errorcode x p] = distchck(2,x,p);

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

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

k = find(x >= 0 & x == round(x) & p > 0 & p <= 1);
if any(k),
   y(k) = p(k) .* (1 - p(k)) .^ x(k);
end

k1 = find(p <= 0 | p > 1);
if any(k1)
   tmp = NaN;
   y(k1) = tmp(ones(size(k1))); 
end

Contact us