CHAPTER06:PROBABILITY AND RANDOM VARIABLES

Example E07 : Pg 6.16

In [1]:
# Page Number: 6.16
# Example 6.7
# Given
# Pdot=2*Pdash and Pdot+Pdash=1
# Therfore, on solving using linear equations
import math 
#a=([1, -2],[1, 1]);
##c=([0],[1]);
#b=1/(a)*c;
Pdash=0.3333333;#b(1,1);
Pdot=0.6666667;#b(2,1);
print'Pdot:',Pdot
print'Pdash:',Pdash
Pdot: 0.6666667
Pdash: 0.3333333

Example E14 : Pg 6.18

In [2]:
# Page Number: 6.18
# Example 6.14
# Given
p=0.1;
q=0.2;
Pm0=0.5;
Pr1bym0=p;
Pr0bym1=q;
# (a) Find Pr0 and Pr1
Pm1=1-Pm0;
Pr0bym0=1-Pr1bym0;
Pr1bym1=1-Pr0bym1;

# By formula
# P(r0)=(P(r0/m0)*P(m0))+(P(r0/m1)*P(m1);
# P(r1)=(P(r1/m0)*P(m0))+(P(r1/m1)*P(m1);
Pr0=(Pr0bym0*Pm0)+(Pr0bym1*Pm1);
Pr1=(Pr1bym0*Pm0)+(Pr1bym1*Pm1);
print'P(r0):',Pr0
print'P(r1):',Pr1
# (b)P(m0/r0)
# Using Bayes Rule
# P(m0/r0)=(P(m0)*P(r0/m0)/P(r0))
Pm0byr0=(Pm0*Pr0bym0)/Pr0;
print'P(m0/r0):',Pm0byr0
# (c)P(m1/r1)
# Using Bayes Rule
# P(m1/r1)=(P(m1)*P(r1/m1)/P(r1))
Pm1byr1=(Pm1*Pr1bym1)/Pr1;
print'P(m1/r1):',Pm1byr1

# (d)Probabilty error
# As Pe=(P(r1/m0)*P(m0))+(P(r0/m1)*P(m1))
Pe=(Pr1bym0*Pm0)+(Pr0bym1*Pm1);
print'Probability error:',Pe

# (e)Probabilty that is transmitted correctly
# As Pc=(P(r0/m0)*P(m0))+(Pr1bym1*Pm1)

Pc=(Pr0bym0*Pm0)+(Pr1bym1*Pm1);
print'Probabilty that is transmitted correctly:',Pc
P(r0): 0.55
P(r1): 0.45
P(m0/r0): 0.818181818182
P(m1/r1): 0.888888888889
Probability error: 0.15
Probabilty that is transmitted correctly: 0.85

Example E16 : Pg 6.21

In [3]:
# Page Number: 6.21
# Example 6.16
# Given
p=0.4;
Pp=p;
q=0.3;
Pn=q;
a=1.; # i start value
b=6.; # i end value
# (a)Probabilty that all pulses are positive
s=1.;
for i in range(1,6):
    s=s*Pp;
print'Probabilty that all pulses are positive:',s

# (b)Pulses are positive ,positive, positive, zero,zero,negative
Pz=1.-(p+q);
s1=(Pp**3.)*(Pz**2.)*Pn;
print'Probabilty that all pulses are positive ,positive, positive, zero,zero,negative:',s1
Probabilty that all pulses are positive: 0.01024
Probabilty that all pulses are positive ,positive, positive, zero,zero,negative: 0.001728

Example E17 : Pg 6.21

In [4]:
# Page Number: 6.21
# Example 6.17
# Given
import math 
P1=0.6;
P0=0.4;
n=5.; # Five digit sequence
j=2.; # two outcomes 0 and 1

# (a)1,1,0,0,0
xf=(math.factorial(n))/((math.factorial(j))*(math.factorial(n-j)));
s=xf*(P1**j)*(P0**(n-j));
print'Probability for 1,1,0,0,0:',s

# (b)atleast 3 1's
# P(X>=3)=1-P(X<=2)
# Here y=1-x
x=0;
for k in range(0,2):
    f=(math.factorial(n))/((math.factorial(k))*(math.factorial(n-k)));
    x=x+(f*((P1**k)*(P0**(n-k))));
y=1.-x;
print'Probability for atleast three 1 s:',y
Probability for 1,1,0,0,0: 0.2304
Probability for atleast three 1 s: 0.91296

Example E20 : Pg 6.23

In [5]:
# Page Number: 6.23
# Example 6.20
# Given
import math 
pe=0.01; # Error probability

# (a) Probabilty of more than one error in 10 recieved digits
n=10.;
# As P(X>1)=1-P(X=0)-P(X=1)
# Let x=P(X>1)
# s=P(X=0)+P(X=1)
s=0;
for t in range(0,1):
    f=(math.factorial(n))/((math.factorial(t))*(math.factorial(n-t)));
    s=s+(f*(pe**t)*((1-pe)**(n-t)));
x=1-s;
print'Probabilty of more than one error in 10 recieved digits:',x

# (b)Using Poisson approximation
# P(X=k)~[{(%exp)**(-n*p)}*{((n*p)**k)}]/k factorial
s1=0;
for k in range(0,1):
    j=math.factorial(k);
    s1=s1+((math.exp(-n*pe))*(((n*pe)**k)))/j;
x1=1.-s1;
print'Using Poisson Approximation:',x1
Probabilty of more than one error in 10 recieved digits: 0.0956179249912
Using Poisson Approximation: 0.095162581964

Example E23 : Pg 6.23

In [6]:
# Page Number: 6.23
# Example 6.23
# We find, k=1/(b-a)
# (b) if a=1 and b=2,P(|x|<c) where c=1/2
a=-1.;
b=2.;
c=1./2.;

k=1./(b-a);
# P(|x|<c) = P(-c<=x<=c)
# Let y
x0=-c;x1=c;
y=1.;#integrate('1','x',x0,x1);
y1=k*y;
print'P(|x|<c):',y1
P(|x|<c): 0.333333333333

Example E41 : Pg 6.34

In [7]:
# Page Number: 6.34
# Example 6.41
# Given
import math 
n=16.; # binary digits
p=0.01; # Probabilty error due to noise

# (a) Average errors per block
# E(X)=n*p
EofX=n*p;
print'Average errors per block:',EofX

# (b)Varience of errors of block
# s=n*p*(1-p)
s=n*p*(1.-p);
print'Varience of errors per block:',s


# (c) Probability that number of errors per block is bgeater or equal than 4
i=4.;
# AsP(X>=4)=1=P(X<=3)
P3=0;
for k in range(0,3):
    f=(math.factorial(n))/((math.factorial(k))*(math.factorial(n-k)));
    P3=P3+(f*(p**k)*((1-p)**(n-k)));
P4=1.-P3;
print'Probability that number of errors per block is bgeater or equal than 4:',P4
Average errors per block: 0.16
Varience of errors per block: 0.1584
Probability that number of errors per block is bgeater or equal than 4: 0.000507942409291