function b = binomd(n,p)
%BINOMD calculates the value of the binomial distribution
%
%Call     b = binomd(n,p) where
%      n = the maximum integer at which the output is required
%      p = simple probabability of the event
%      b = the distribution values for r = 0..n
%
%Note that the distribution is defined for integer arguments only
%

%Copyright (c) H.E. Hanrahan, University of the Witwatersrand, Johannesburg
%Revision:  12 Jan 1992                 e-mail: hanrahan@odie.ee.wits.ac.za

nn = [1 cumprod(1:n+1)]; %0!, 1!, .. ,(n+1)!
q = 1-p;
b =[]
for r = 0:n,
 b = [b nn(n+1)* p.^r.*q.^(n-r)/(nn(r+1)*nn(n-r+1))];
end;
