statsizechk matlab,求解释 poissrnd的源程序

function r = poissrnd(lambda,varargin)

%POISSRND Random arrays from the Poisson distribution.

%   R = POISSRND(LAMBDA) returns an array of random numbers chosen from the

%   Poisson distribution with parameter LAMBDA.  The size of R is the size

%   of LAMBDA.

%

%   R = POISSRND(LAMBDA,M,N,...) or R = POISSRND(LAMBDA,[M,N,...]) returns

%   an M-by-N-by-... array.

%

%   See also POISSCDF, POISSINV, POISSPDF, POISSTAT, RANDOM.

%   POISSRND uses a waiting time method for small values of LAMBDA,

%   and Ahrens' and Dieter's method for larger values of LAMBDA.

%   References:

%      [1]  Devroye, L. (1986) Non-Uniform Random Variate Generation,

%           Springer-Verlag.

%   Copyright 1993-2006 The MathWorks, Inc.

%   $Revision: 2.12.4.6 $  $Date: 2006/10/02 16:34:59 $

if nargin < 1

error('stats:poissrnd:TooFewInputs','Requires at least one input argument.');

end

[err, sizeOut, numelOut] = statsizechk(1,lambda,varargin{:});

if err > 0

error('stats:poissrnd:InputSizeMismatch','Size information is inconsistent.');

end

lambda(lambda < 0) = NaN;

if isscalar(lambda)

lambda = repmat(lambda, numelOut, 1);

else

lambda = lambda(:);

end

%Initialize r to zero.

if isa(lambda,'single')

r = zeros(sizeOut,'single');

else

r = zeros(sizeOut);

end

r(isinf(lambda)) = Inf;

% For large lambda, use the method of Ahrens and Dieter as

% described in Knuth, Volume 2, 1998 edition.

k = find(15 <= lambda & lambda < Inf);

if ~isempty(k)

alpha = 7/8;

lk = lambda(k);

m = floor(alpha * lk);

% Generate m waiting times, all at once

x = randg(m);

t = (x <= lk);

% If we did not overshoot, then the number of additional times

% has a Poisson distribution with a smaller mean.

r(k(t)) = m(t) + poissrnd(lk(t)-x(t));

% If we did overshoot, then the times up to m-1 are uniformly

% distributed on the interval to x, so the count of times less

% than lambda has a binomial distribution.

r(k(~t)) = binornd(m(~t)-1, lk(~t)./x(~t));

end

% For small lambda, generate and count waiting times.

j = find(lambda < 15);

p = zeros(numel(j),1);

while ~isempty(j)

p = p - log(rand(numel(j),1));

t = (p < lambda(j));

j = j(t);

p = p(t);

r(j) = r(j) + 1;

end

% Return NaN if LAMBDA is negative.

r(isnan(lambda)) = NaN;

以上为matlab中poissrnd的源程序,那位高人能帮忙解释下这个程序,具体说的什么意思。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值