binornd - Binomial random numbers

Syntax

R = binornd(N,P)
R = binornd(N,P,v)
R = binornd(N,p,m,n)

Description

R = binornd(N,P) generates random numbers from the binomial distribution with parameters specified by N and P. N and P can be vectors, matrices, or multidimensional arrays that have the same size, which is also the size of R. A scalar input for N or P is expanded to a constant array with the same dimensions as the other input.

R = binornd(N,P,v) generates an array R of size v containing random numbers from the binomial distribution with parameters N and P, where v is a row vector. If v is a 1-by-2 vector, R is a matrix with v(1) rows and v(2) columns. If v is 1-by-n, R is an n-dimensional array.

R = binornd(N,p,m,n) generates an m-by-n matrix containing random numbers from the binomial distribution with parameters N and P.

Algorithm

The binornd function uses the direct method using the definition of the binomial distribution as a sum of Bernoulli random variables.

Example

n = 10:10:60;

r1 = binornd(n,1./n)
r1 =
   2   1   0   1   1   2

r2 = binornd(n,1./n,[1 6])
r2 =
   0   1   2   1   3   1

r3 = binornd(n,1./n,1,6)
r3 =
   0   1   1   1   0   3

See Also

random, binopdf, binocdf, binoinv, binostat, binofit

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS