# Chapter 10 : Introduction to theory of probability¶

## page no 437 Ex 10.1¶

In [2]:
from __future__ import division
# referred to fig 10.1 on the page no. 435
# the occurance of each outcome is essumed to be equal.
n=8 # number of outcomes
p=1/n#
print "probability of each outcome=%0.2f"%p

probability of each outcome=0.12


## page no 438 Ex no 10.3¶

In [1]:
from __future__ import division
m=6 # enter the number of faces
n=2# enter the number of dice
l=m**n ## total number of outcomes = 36
a=7 #"enter the number which is to be obtained as the sum of dice
c=0 # # counter value for favorable outcome
for i in range(1,7):
for j in range(1,7):
if (i+j==a):
c=c+1#
else :
continue

p=c/l#
print "probability = %0.4f"%p


probability = 0.1667


## page no 438 Ex no 10.4¶

In [4]:
from numpy.random import gamma
from __future__ import division
m=2# the number of faces
n=4 #the number of tosses
l=m**n ## l is total number of outcomes = 16
p=gamma (n+1)/(gamma(n+1-a) * gamma (a+1))## to find combination
print "probability = %0.4f"%(p/l)

probability = 0.4075


## page no 440 Ex no 10.5¶

In [2]:
from __future__ import division
a=52# # total no of cards in a deck
b=6# the no of cards to be drawn
pA1= b/a## probability of getting first red ace =pA1
#the cards are drawn in succession without replacement, therefore the probability that the 2nd card will be the red ace = pA2
pA2=1/(a-1)#
p= pA1*pA2
print "total probability = %0.4f"%p

total probability = 0.0023


## page no 441 Ex no 10.6¶

In [12]:
from numpy.random import gamma
from __future__ import division

# This problem is based on Bernoulli Trials formula which is P( k successes in n trials ) = n!*p**k *(1-p)**(n-k)/k!*(n-k)!22
# hence the probability of finding 2 digits wrong in a sequence of 8 digits is

k=2 # no. of successes
p= 1e-5# probability of success
n=8 #"no. of trials
A=gamma (n+1)* (p**k)*((1-p)**(n-k))/(gamma(k)*gamma(n+1-k))#
print "probability = %0.2e"%A

probability = 1.02e-10


## page no 446 Ex no 10.9¶

In [3]:
from __future__ import division
m=6 # enter the number of faces
n=3 # enter the number of dice
l=m**n ## l is total number of outcomes
a=8# the number which is to be obtained as the sum of dice
c=0 # # counter value for favorable outcome
for i in range(1,7):
for j in range(1,7):
if(i+j==a):
c=c+1
else :
continue

p=c/l#
print "probability = %.4f"%p

probability = 0.0231


## page no 447 Ex no 10.10¶

In [4]:
from __future__ import division
Pe=0.6898 # error probability
Q= 0.2567 # the probability of transmitting 1 #Hence probability of transmitting zero is 1-Q = P
P=1-Q#
Px_1=Q#
Px0=P#
# If x and y are transmitted digit and received digit then for BSC P(y=0/x=1) = P(y=1/x=0) = Pe , P(y=0/x=10) = P(y=1/x=1) = 1-Pe
# to find the probability of receiving 1 is Py(1) = Px(0)*P(y=1/x=0) + Px(1)*P(y=1/x=1)
Py_1= ((1-Q)* Pe) + (Q *(1-Pe))#
print "Py(1) = %0.4f"%Py_1
Py0=((1-Q)*(1-Pe)) + (Q*Pe)
print "Py0=%.4f"%Py0

Py(1) = 0.5924
Py0=0.4076


## page no 448 Ex 10.11¶

In [5]:
from __future__ import division
Px0=.4
Px1=.6
PE0=10**-6
PE1=10**-4 ## given
PE=(Px0*PE0) + (Px1*PE1)# formula for probability of error
print "probability of error = %.2e"%PE

probability of error = 6.04e-05


## page no 472 Ex no 10.20¶

In [4]:
from __future__ import division
from math import pi,sqrt,exp
#Gaussian PDF: Q(x)= %e**((-x**2)/2)/ (x*sqrt(2*pi))
x=2.5 #  input for the function Q
Q_x = (exp(-(x**2)/2))/ (x*sqrt(2*pi))
P=1-(2*Q_x)#
print "width or spread of Gaussian PDF = %.3f"%P
## P gives the width or spread of Gaussian PDF

width or spread of Gaussian PDF = 0.986


## page no 479 Ex no 10.21¶

In [11]:
from __future__ import division
from math import log
# formula for estimate error E is E = mk** - mk = a1* mk-1 +a2* mk-2 -mk
#given: various values of correlation (mk*mk)'= (m**2)',(mk*mk-1)'= .825* (m**2)',(mk*mk-2)'= .562*(m**2)',(mk*mk-3)'= .825*(m**2)' , R02=.562(m**2)', a1=1.1314, a2= -0.3714
# mean square error is given by I=(E**2)'=[1-((.825*a1)+(.562*a2))]*(m**2)'= .2753*(m**2)'

m=1#
I=.2753*(m**2)#
S=10*log ((m**2)/I)#
print "SNR improvement = %0.2f dB"%S

SNR improvement = 12.90 dB