next up previous contents
Next: RANDNBIN Generate Negative Binomial Up: Random Number Generation Previous: RANDP Generate Poisson Random   Contents

Subsections

RANDBIN Generate Binomial Random Variables

Usage

Generates random variables with a binomial distribution. The general syntax for its use is

   y = randbin(N,p)

where N is a vector representing the number of Bernoulli trials, and p is the success probability associated with each trial.

Function Internals

A Binomial random variable describes the number of successful outcomes from N Bernoulli trials, with the probability of success in each trial being p. The probability distribution is

$\displaystyle P(n) = \frac{N!}{n!(N-n)!}p^n(1-p)^{N-n}
$

Example

Here we generate 10 binomial random variables, corresponding to N=100 trials, each with probability p=0.1, using both randbin and then again using rand (to simulate the trials):

--> randbin(100,.1*ones(1,10))
ans = 
  <uint32>  - size: [1 10]
 
Columns 1 to 5
            9             9            10             8             9  
 
Columns 6 to 10
            7            10            13             9             9  
--> sum(rand(100,10)<0.1)
ans = 
  <int32>  - size: [1 10]
 
Columns 1 to 5
             9             11              6             10              9  
 
Columns 6 to 10
             6             11             16              9              7



Samit K. Basu 2005-03-16