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

geometric_cdf(x,p)
function y = geometric_cdf(x,p)
%GEOMETRIC_CDF Geometric cumulative distribution function.
%   Y=GEOMETRIC_CDF(X,P) returns the geometric cumulative distribution
%   function 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:53 $

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));

xx = floor(x);
k = find(xx >= 0 & p > 0 & p <= 1);
if any(k)
    y(k) = 1 - (1 - p(k)) .^ (xx(k) + 1);
end

k2 = find(p == 1 & x ~= 0);
if any(k2)
    y(k2) = zeros(size(k2));
end

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

Contact us