{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter - 10 : Introduction to theory of probability" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 437 Ex 10.1" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability of each outcome=0.12\n" ] } ], "source": [ "from __future__ import division\n", "# referred to fig 10.1 on the page no. 435\n", "# the occurance of each outcome is essumed to be equal.\n", "n=8 # number of outcomes\n", "p=1/n#\n", "print \"probability of each outcome=%0.2f\"%p" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 438 Ex no 10.3" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability = 0.1667\n" ] } ], "source": [ "from __future__ import division\n", "m=6 # enter the number of faces \n", "n=2# enter the number of dice \n", "l=m**n ## total number of outcomes = 36\n", "a=7 #\"enter the number which is to be obtained as the sum of dice\n", "c=0 # # counter value for favorable outcome\n", "for i in range(1,7):\n", " for j in range(1,7):\n", " if (i+j==a):\n", " c=c+1#\n", " else :\n", " continue\n", " \n", " \n", "\n", "p=c/l#\n", "print \"probability = %0.4f\"%p\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 438 Ex no 10.4" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability = 0.4075\n" ] } ], "source": [ "from numpy.random import gamma\n", "from __future__ import division\n", "m=2# the number of faces \n", "n=4 #the number of tosses\n", "l=m**n ## l is total number of outcomes = 16\n", "a=2 #exact no of heads\n", "p=gamma (n+1)/(gamma(n+1-a) * gamma (a+1))## to find combination\n", "print \"probability = %0.4f\"%(p/l)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 440 Ex no 10.5" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "total probability = 0.0023\n" ] } ], "source": [ "from __future__ import division\n", "a=52# # total no of cards in a deck\n", "b=6# the no of cards to be drawn\n", "pA1= b/a## probability of getting first red ace =pA1\n", "#the cards are drawn in succession without replacement, therefore the probability that the 2nd card will be the red ace = pA2\n", "pA2=1/(a-1)#\n", "p= pA1*pA2\n", "print \"total probability = %0.4f\"%p" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 441 Ex no 10.6" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability = 1.04e-10\n" ] } ], "source": [ "from numpy.random import gamma\n", "from __future__ import division\n", "\n", "# 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\n", "# hence the probability of finding 2 digits wrong in a sequence of 8 digits is\n", "\n", "k=2 # no. of successes\n", "p= 1e-5# probability of success\n", "n=8 #\"no. of trials\n", "A=gamma (n+1)* (p**k)*((1-p)**(n-k))/(gamma(k)*gamma(n+1-k))#\n", "print \"probability = %0.2e\"%A" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 446 Ex no 10.9" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability = 0.0231481481481\n" ] } ], "source": [ "from __future__ import division\n", "m=6 # enter the number of faces\n", "n=3 # enter the number of dice\n", "l=m**n ## l is total number of outcomes \n", "a=8# the number which is to be obtained as the sum of dice\n", "c=0 # # counter value for favorable outcome\n", "for i in range(1,7):\n", " for j in range(1,7):\n", " if(i+j==a):\n", " c=c+1\n", " else :\n", " continue\n", " \n", "p=c/l#\n", "print \"probability = \",p\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 447 Ex no 10.10" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Py(1) = 0.59235668\n", "Py0= 0.40764332\n" ] } ], "source": [ "from __future__ import division\n", "Pe=0.6898 # error probability\n", "Q= 0.2567 # the probability of transmitting 1 #Hence probability of transmitting zero is 1-Q = P\n", "P=1-Q#\n", "Px_1=Q#\n", "Px0=P#\n", "# 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\n", "# to find the probability of receiving 1 is Py(1) = Px(0)*P(y=1/x=0) + Px(1)*P(y=1/x=1)\n", "Py_1= ((1-Q)* Pe) + (Q *(1-Pe))#\n", "print \"Py(1) = \",Py_1\n", "Py0=((1-Q)*(1-Pe)) + (Q*Pe)\n", "print \"Py0=\",Py0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 448 Ex 10.11" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability of error = 6.04e-05\n" ] } ], "source": [ "from __future__ import division\n", "Px0=.4\n", "Px1=.6 \n", "PE0=10**-6 \n", "PE1=10**-4 ## given\n", "PE=(Px0*PE0) + (Px1*PE1)# formula for probability of error\n", "print \"probability of error = \",PE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 472 Ex no 10.20" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "width or spread of Gaussian PDF = 0.985977359605\n" ] } ], "source": [ "from __future__ import division\n", "from math import pi,sqrt,exp\n", "#Gaussian PDF: Q(x)= %e**((-x**2)/2)/ (x*sqrt(2*pi))\n", "x=2.5 # input for the function Q \n", "Q_x = (exp(-(x**2)/2))/ (x*sqrt(2*pi))\n", "P=1-(2*Q_x)#\n", "print \"width or spread of Gaussian PDF =\",P\n", "## P gives the width or spread of Gaussian PDF" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## page no 479 Ex no 10.21" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SNR improvement = 12.90 dB\n" ] } ], "source": [ "from __future__ import division\n", "from math import log\n", "# formula for estimate error E is E = mk** - mk = a1* mk-1 +a2* mk-2 -mk\n", "#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\n", "# mean square error is given by I=(E**2)'=[1-((.825*a1)+(.562*a2))]*(m**2)'= .2753*(m**2)'\n", "\n", "m=1#\n", "I=.2753*(m**2)#\n", "S=10*log ((m**2)/I)#\n", "print \"SNR improvement = %0.2f dB\"%S" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }