blob: 8d98ca511841452fd90e01f2eb0883d30eb78f41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
//Chapter 07: Discrete Probability
clc;
clear;
p0=0.9 //prob of bit 0 generation
p1=1-p0 //prob of bit 1 generation
total_bits=10 //total bits generated
reqd_bits=8 //reqd bits out of totalbits generated
function result=combination(n,r) //function definition
i=n
num=1
denominator=1
l=(n-r)+1
u=n
for i=l:u //to compute the value of the numerator
num=num*i
end
for j=1:r //to compute the value of the denominator
denominator=denominator*j
end
result=num/denominator
return result
endfunction
//Using theorem 2
prob_eight_0=combination(total_bits,reqd_bits)*((p0)**reqd_bits)*((p1)**(total_bits-reqd_bits))
disp(prob_eight_0,'Probability of exactly eight 0 bits generated is')
|