# HG changeset patch # User Rik # Date 1360821219 28800 # Node ID 444de2c0af0e111d9579c680ab496bda4adaa394 # Parent c3057d80cf91c5544d008047dbf84ac8a0f3e564 binopdf.m: Ensure Matlab compatibility for boundary values (bug #38292). * scripts/statistics/distributions/binopdf.m: Return 1 for special cases of 'binopdf (0,n,0)' and 'binopdf (n,n,1)'. diff -r c3057d80cf91 -r 444de2c0af0e scripts/statistics/distributions/binopdf.m --- a/scripts/statistics/distributions/binopdf.m Wed Feb 06 21:45:04 2013 +0000 +++ b/scripts/statistics/distributions/binopdf.m Wed Feb 13 21:53:39 2013 -0800 @@ -64,6 +64,12 @@ + x(k).*log (p(k)) + (n(k)-x(k)).*log (1-p(k))); endif + ## Special case inputs + ksp = k & (p == 0) & (x == 0); + pdf(ksp) = 1; + ksp = k & (p == 1) & (x == n); + pdf(ksp) = 1; + endfunction @@ -82,6 +88,11 @@ %!assert (binopdf (x, 2, 0.5*[0 -1 NaN 3 1]), [0 NaN NaN NaN 0]) %!assert (binopdf ([x, NaN], 2, 0.5), [y, NaN], tol) +## Test Special input values +%!assert (binopdf (0, 3, 0), 1); +%!assert (binopdf (2, 2, 1), 1); +%!assert (binopdf (1, 2, 1), 0); + %% Test class of input preserved %!assert (binopdf (single ([x, NaN]), 2, 0.5), single ([y, NaN])) %!assert (binopdf ([x, NaN], single (2), 0.5), single ([y, NaN]))