changeset 14583:89504d0a5c5b stable

poissrnd should return zero when lambda = 0. (Bug # 36326) poissrnd.m: poissonrnd should return zero when lambda = 0. Add demos.
author Ben Abbott <bpabbott@mac.com>
date Mon, 30 Apr 2012 22:19:14 -0400
parents 000cd393f3c1
children 6250e1232c9c
files scripts/statistics/distributions/poissrnd.m
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/statistics/distributions/poissrnd.m	Thu Apr 19 16:24:14 2012 -0400
+++ b/scripts/statistics/distributions/poissrnd.m	Mon Apr 30 22:19:14 2012 -0400
@@ -76,7 +76,7 @@
   endif
 
   if (isscalar (lambda))
-    if (lambda > 0 && lambda < Inf)
+    if (lambda >= 0 && lambda < Inf)
       rnd = randp (lambda, sz);
       if (strcmp (cls, "single"))
         rnd = single (rnd);
@@ -87,13 +87,12 @@
   else
     rnd = NaN (sz, cls);
 
-    k = (lambda > 0) & (lambda < Inf);
+    k = (lambda >= 0) & (lambda < Inf);
     rnd(k) = randp (lambda(k));
   endif
 
 endfunction
 
-
 %!assert(size (poissrnd (2)), [1, 1]);
 %!assert(size (poissrnd (ones(2,1))), [2, 1]);
 %!assert(size (poissrnd (ones(2,2))), [2, 2]);
@@ -118,3 +117,6 @@
 %!error poissrnd (ones(2,2), [3, 2])
 %!error poissrnd (ones(2,2), 2, 3)
 
+%!assert (poissrnd (0, 1, 1), 0)
+%!assert (poissrnd ([0, 0, 0], [1, 3]), [0 0 0])
+