% Bennulli (M, N, P)% M test number% N event generated number% P event incident The probability of occurrence of P event %% Author Zhang Xiaohui% 2005-03-13% Function C = Bernoulli (M, n, p)
IF m <1 | round (m) ~ = m error ('m should be positive integers!'); END
[a b] = size (n);
IF a * b == 1 if n <0 | round (n) ~ = n | n> m M Error ('N should be no more than M non-negative integer!'); end if P <= 0 | P> = 1 Error ('P should be a real number of 0 to 1!'); END C = Nchoosek (m, n) * p ^ n * (1-p) ^ (mn); Else Error ('N is not supported ! '); END
The following is the result in matlab:
>> C = Bernoulli (3, 3, 0.8) c = 0.5120
>>