ex5m2_1.doc

advertisement
Random Signals for Engineers using MATLAB and Mathcad
Copyright  1999 Springer Verlag NY
Example 2.1 Binomial Distribution
In this example we develop the functions that are needed to express the probabilities of
random variables that obey a Binomial law. We will also develop closed form expressions that
will enable us to sum the individual probabilities and show that, indeed, the probability of some
event occurring according to binomial law is equal to unity. We employ the symbolic capability
of Matlab to manipulate some of the required expressions.
Let us expand (p + q) to various powers. We make use of the Expand Expression symbolic
capability of Matlab to form the right hand side of the equations
syms p q;
d= p+q
f= (p+q)^2
d =
p+q
f =
(p+q)^2
g= (p+q)^3;
h= (p+q)^4;
pretty(d), pretty(expand(f)), pretty(expand(g)), pretty(expand(h))
p + q
2
2
p
+ 2 p q + q
3
p
4
p
2
+ 3 p
2
q + 3 p q
3
+ 4 p
2
q + 6 p
3
+ q
2
q
3
+ 4 p q
4
+ q
Comparing the individual term with the probability terms of Section 2.1 we notice that each term
of the sum is equal to the probability that there will be k heads in n successive tosses of a coin.
The coefficient of the pn-k qk terms follows the so-called Pascal Triangle rule. In a Pascal
Triangle each term in each successive row is the sum of the terms to the right and left of the term
in the row above
k ->
n=1
n=2
n=3
n=4
n=5
1 1
2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1
Each of the terms of the Pascal Triangle can be also calculated using the combinatorial formula
that is based upon the factorials of k, n and n-k.
C n, k  
n!
k!n  k !
syms x k
kfac = sym('k!');
n=0:4;
x=(ones(size(n)));
The combinatorial formula can be verified by computing the 4th row of the Pascal Triangle, n =
4
p=subs(kfac,k,4)./(subs(kfac,k,x.*n).*subs(kfac,k,4-x.*n))
p =
[ 1, 4, 6, 4, 1]
Since expanding a polynomial in two variables (binomial) results in the kth probability term the
resultant probability expression is called a Binomial law. The probability of getting k heads in n
coin tosses therefore follows a Binomial probability law. In order to compute the probability that
we will get 0 or 1 or 2 or .. k or .. n heads on the next n tosses, the probabilities from k = 0 .. n are
summed. The events that result for each individual k are mutually exclusive and therefore we
may computer the probability as a sum of the n + 1 individual probabilities. From the left-hand
side of the equations presented we have
 p  q n
 1n  1
This is of course true since p + q = 1. In the next n tosses we must surely get any number of
heads from 0 to n.
We develop and iterative formula to compute the binomial probabilities for k = 0 to n. The
probability term can be expressed as Bk for example for the following parameters
n  6 and
p  0.6 k  0n
syms k n p
Bk=subs(kfac,k,n)/(subs(kfac,k,k)*subs(kfac,k,n-k))*p^k*(1-p)^(n-k);
pretty(Bk)
k
(n - k)
n! p (1 - p)
-------------------k! (n - k)!
The expression for Bk+1 is found by substitution of k + 1 for k using Matlab. Dividing the two
expressions and simplifying the right hand side we obtain the iteration formula.
Bk1=subs(kfac,k,n)/(subs(kfac,k,k+1)*subs(kfac,k,n-k-1))*p^(k+1)*(1p)^(n-k-1);
Biter =simple(Bk1/Bk);
pretty(Biter)
(n - k) p
--------------(k + 1) (1 - p)
Computing B0 initializes the iteration. Since the array b(i) is indexed from 1 in Matlab, we adjust
the iteration factor and compute the array from 1 to 7 for n=6
p=0.6;
b(1)=(1-p)^6;
for k=1:6
b(k+1)=p*(6-k+1)*b(k)/((1-p)*(k));
end
b
b =
0.0041
0.0369
0.1382
0.2765
0.3110
0.1866
0.0467
PROBLEM: A simple example of the use of the Binomial distribution is given. Let us assume
that it takes at least 3 machines out of 6 to complete a job. We are given that probability that any
one machine will not fail before the end of the job is 0.6. What is the probability that we can
complete the job?
SOLUTION: We need to compute the probability that 3 or 4 or 5 or 6 machines last for the entire
job. The probability of one machine completes the job is 0.6. This is analogous to the coin toss
problem where in a single toss, a head results with probability p, therefore p = 0.6. The outcomes
that are favorable are k = 3 ..6. For Matlab we change the index to be 4 to 7. We sum these
probabilities to obtain the desired probability, since these outcomes are mutually exclusive. Using
a new index variable, v, to sum over the required range we have
v=4:7
sum(b(v))
v =
4
5
ans =
0.8208
6
7
The probability that there will be at least 3 machine out of 6 that function for the complete job is
P = 0.821.

Download