% RANDBERN file randbern.m Random number of Bernoulli trials
% Version of 12/19/96; notation modified 5/20/97
% Joint and marginal distributions for a random number of Bernoulli trials
% N is the number of trials
% S is the number of successes
p = input('Enter the probability of success ');
N = input('Enter VALUES of N ');
PN = input('Enter PROBABILITIES for N ');
n = length(N);
m = max(N);
S = 0:m;
P = zeros(n,m+1);
for i = 1:n
P(i,1:N(i)+1) = PN(i)*ibinom(N(i),p,0:N(i));
end
PS = sum(P);
P = rot90(P);
disp('Joint distribution N, S, P, and marginal PS')