{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Chapter7 - Probability Theory"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.1 Pg 152"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sample space for the event that an even or a prime number occurs = [2 3 4 5 6]\n",
"sample space for the event that an odd prime number occurs = [3 5]\n",
"sample space for the event that a prime number does not occur = [1 4 6]\n",
"sample space for the event in which only heads appear = ['000']\n",
"Experiment:tossing a coin until a head appears and then counting the number of times the coin is tossed\n",
"Since every positive integer is an element of S,the sample space is infinite\n"
]
}
],
"source": [
"from numpy import intersect1d, setdiff1d, union1d,inf\n",
"from __future__ import division\n",
"S=[1,2,3,4,5,6] #sample space for the rolling of a die\n",
"A=[2,4,6] #event that an even number occurs\n",
"B=[1,3,5] #event that an odd number occurs\n",
"C=[2,3,5] #event that a prime number occurs\n",
"print 'sample space for the event that an even or a prime number occurs = ',union1d(A,C)\n",
"print 'sample space for the event that an odd prime number occurs = ',intersect1d(B,C)\n",
"print 'sample space for the event that a prime number does not occur = ',setdiff1d(S,C) #It is the complement of the set C.\n",
"intersect1d(A,B) #It is a null set or null vector since there can't occur an even and an odd number simultaneously\n",
" \n",
"H=0# #\"head\" face of a coin\n",
"T=1# #\"tail\" face of a coin\n",
"S=[\"000\",\"001\",\"010\",\"011\",\"100\",\"101\",\"110\",\"111\"] # #sample space for the toss of a coin three times\n",
"A=[\"000\",\"001\",\"100\"]# #event that two more or more heads appear consecutively\n",
"B=[\"000\",\"111\"]# #event that all tosses are the same\n",
"print 'sample space for the event in which only heads appear = ',intersect1d(A,B)\n",
" \n",
"print 'Experiment:tossing a coin until a head appears and then counting the number of times the coin is tossed'\n",
"S=[1,2,3,4,5,inf] #The sample space has infinite elements in it\n",
"print \"Since every positive integer is an element of S,the sample space is infinite\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.2 Pg 153"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment:three coins are tossed and the number of heads are observed\n",
"the probability space is as follows \n",
"A is the event that atleast one head appears and B is the event that all heads or all tails appear \n",
"probability of occurrence of event A = 0.875\n",
"probability of occurrence of event B = 0.25\n"
]
}
],
"source": [
"print 'Experiment:three coins are tossed and the number of heads are observed'\n",
"S=[0,1,2,3]# #the sample space for the experiment where 0 implies no heads,1 implies only one head out of the three coins and so on\n",
"print \"the probability space is as follows \"\n",
"P0=1/8# #probability of getting no head on any of the coins i.e TTT\n",
"P1=3/8# #probability of getting only one head on any of the coins, out of the three coins i.e HTT,THT,TTH\n",
"P2=3/8# #probability of getting two heads, out of the three coins i.e THH,HTH,HHT\n",
"P3=1/8# #probability of getting all the three heads i.e HHH\n",
"print \"A is the event that atleast one head appears and B is the event that all heads or all tails appear \"\n",
"A=[1,2,3]# # HHH,HHT,HTH,HTT,THH,THT,TTH\n",
"B=[0,3]# #HHH,TTT\n",
"PA=P1+P2+P3# \n",
"print 'probability of occurrence of event A = ',PA\n",
"PB=P0+P3# \n",
"print 'probability of occurrence of event B = ',PB "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.3 Pg 154"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment: a card is selected from a deck of 52 cards \n",
"A is the event of the selected card being a spade \n",
"B is the event of the selected card being a face card \n",
"probability of selecting a spade = 1/4\n",
"probability of selecting a face card = 3/13\n",
"probability of selecting a spade face card is: 3/52\n"
]
}
],
"source": [
"from fractions import Fraction\n",
"print \"Experiment: a card is selected from a deck of 52 cards \"\n",
"print \"A is the event of the selected card being a spade \"\n",
"print \"B is the event of the selected card being a face card \"\n",
"t=52 # #the total number of cards\n",
"s=13# #number of spades\n",
"PA= s/t# \n",
"print 'probability of selecting a spade = ',Fraction(PA).limit_denominator(100)\n",
"f=12# #number of face cards(jack,queen,king)\n",
"PB=f/t#\n",
"print 'probability of selecting a face card = ',Fraction(PB).limit_denominator(100)\n",
"sf=3# #number of spade face cards\n",
"Psf=sf/t#\n",
"print \"probability of selecting a spade face card is:\",Fraction(Psf).limit_denominator(100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.4 Pg 155"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment: selection of a student out of 100 students \n",
"probability of the selected student taking mathematics or chemistry = 2/5\n"
]
}
],
"source": [
"print \"Experiment: selection of a student out of 100 students \"\n",
"M=30# #no of students taking mathematics\n",
"C=20# #no of students taking chemistry\n",
"T=100# #total no. of students\n",
"PM = M/T #probability of the selected student taking mathematics\n",
"PC = C/T #probability of the selected student taking chemistry\n",
"MnC=10# #no of students taking mathematics and chemistry\n",
"PMnC = MnC/T #probability of the selected student taking mathematics and chemistry both\n",
"PMorC = PM+PC-PMnC# \n",
"print 'probability of the selected student taking mathematics or chemistry = ',Fraction(PMorC).limit_denominator(100)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.6 Pg 156"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A bag contains 12 items of which four are defective.Three items are drawn at random,one after the other\n",
"probability that all three items are non defective = 14/55\n"
]
}
],
"source": [
"print \"A bag contains 12 items of which four are defective.Three items are drawn at random,one after the other\"\n",
"s=12# #total itmes in the bag\n",
"d=4# #defective items in the bag\n",
"Pf=(s-d)/s # #probability that the first item drawn is non defective\n",
"Pe=Pf*((s-d-1)/(s-1))*((s-d-2)/(s-2))\n",
"print 'probability that all three items are non defective = ',Fraction(Pe).limit_denominator(100)\n",
"#after the first item is chosen,the second item is to be chosen from 1 less than the original number of items in the box and similarly the number of non defective items gets decreased by 1.Similarly ,for the third draw of item from the box"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.7 Pg 157"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"probability of A is = 0.5\n",
"probability of B is = 0.5\n",
"probability of C is = 0.25\n",
"probability of the event AnB = 0.25\n",
"probability of the event AnC = 0.125\n",
"probability of the event BnC = 0.25\n",
"A and B are independent\n",
"A and C are independent\n",
"B and C are dependent\n"
]
}
],
"source": [
"from numpy import intersect1d\n",
"H=1# #heads of a coin\n",
"T=2# #tails of the coin\n",
"S=[111,112,121,122,211,212,221,222] #sample space for the toss of a coin three times. 111 implies heads all three times,112 implies heads on first two tosses and tails on the third toss\n",
"A=[111,112,121,122]# #event that first toss is heads\n",
"B=[111,112,211,212]# #event that second toss is heads\n",
"C=[112,211]# #event that exactly two heads appear in a row\n",
"PA=len(A)/len(S)\n",
"print 'probability of A is = ',PA\n",
"PB=len(B)/len(S)\n",
"print 'probability of B is = ',PB\n",
"PC=len(C)/len(S)\n",
"print 'probability of C is = ',PC\n",
"AnB=intersect1d(A,B)\n",
"AnC=intersect1d(A,C)\n",
"BnC=intersect1d(B,C)\n",
"PAnB= len(AnB)/len(S)\n",
"print 'probability of the event AnB = ',PAnB\n",
"PAnC= len(AnC)/len(S)#\n",
"print 'probability of the event AnC = ',PAnC \n",
"PBnC= len(BnC)/len(S)\n",
"print 'probability of the event BnC = ',PBnC\n",
"if((PA*PB)==PAnB):\n",
" print \"A and B are independent\"\n",
"else:\n",
" print \"A and B are dependent\"\n",
"\n",
"if((PA*PC)==PAnC):\n",
" print \"A and C are independent\"\n",
"else:\n",
" print \"A and C are dependent\"\n",
"if((PB*PC)==PBnC):\n",
" print \"B and C are independent\"\n",
"else:\n",
" print \"B and C are dependent\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.8 Pg 157"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment: A and B both shoot at a target\n",
"A and B are independent events so PA*PB will be equal to probability of the event of A and B both hitting the target i.e PAnB\n",
"probability of atleast one of them hitting the target = 0.55\n"
]
}
],
"source": [
"print \"Experiment: A and B both shoot at a target\"\n",
"PA=1/4# #given probability of A hitting the target\n",
"PB=2/5# #given probability of B hitting the target\n",
"print \"A and B are independent events so PA*PB will be equal to probability of the event of A and B both hitting the target i.e PAnB\"\n",
"PAnB=PA*PB#\n",
"PAorB=PA+PB-PAnB#\n",
"print'probability of atleast one of them hitting the target = ', PAorB"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.9 Pg 158"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment: Three horses race together twice\n",
"probability of third horse winning the first race and first horse winning the second race is = 1/12\n"
]
}
],
"source": [
"print \"Experiment: Three horses race together twice\"\n",
"Ph1=1/2# #probability of first horse winning the race\n",
"Ph2=1/3# #probability of second horse winning the race\n",
"Ph3=1/6# #probability of third horse winning the race\n",
"S=[11,12,13,21,22,23,31,32,33] #sample space where 11 implies first horse winning the first and second race both,12 implies first horse winning the first race and second horse winning the second race and so on\n",
"P11=Ph1*Ph1 #probability of first horse winning both races\n",
"P12=Ph1*Ph2 #probability of first horse winning the first race and second horse winning the second race\n",
"P13=Ph1*Ph3 #probability of first horse winning the first race and third horse winning the second race\n",
"P21=Ph2*Ph1 #probability of second horse winning the first race and first horse winning the second race\n",
"P22=Ph2*Ph2 #probability of second horse winning both the races\n",
"P23=Ph2*Ph3 #probability of second horse winning the first race and third horse winning the second race\n",
"P31=Ph3*Ph1 #probability of third horse winning the first race and first horse winning the second race\n",
"P32=Ph3*Ph2 #probability of third horse winning the first race and second horse winning the second race\n",
"P33=Ph3*Ph3 #probability of third horse winning both the races \n",
"print 'probability of third horse winning the first race and first horse winning the second race is = ',Fraction(P31).limit_denominator(100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.10 Pg 158"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"probability of getting exactly two heads (i.e k=2) = 15/64\n",
"probability of getting atleast four heads(i.e k=4,5 or 6) = 11/32\n",
"probability of getting one or more heads = 63/64\n"
]
}
],
"source": [
"from scipy.misc import factorial\n",
"n=6# #number of times a fair coin is tossed and getting a heads is a success\n",
"p=1/2# #probability of getting a heads\n",
"q=1/2 # #probability of not getting a heads\n",
"P2=(factorial(6)/(factorial(6-2)*factorial(2)))*p**2*q**(6-2)# \n",
"print 'probability of getting exactly two heads (i.e k=2) = ',Fraction(P2).limit_denominator(100)\n",
"\n",
"P4=(factorial(6)/(factorial(6-4)*factorial(4)))*p**4*q**(6-4)# #probabilty of getting four heads\n",
"P5=(factorial(6)/(factorial(6-5)*factorial(5)))*p**5*q**(6-5)# #probabilty of getting five heads\n",
"P6=(factorial(6)/(factorial(6-6)*factorial(6)))*p**6*q**(6-6)# #probabilty of getting five heads\n",
"PA=P4+P5+P6 # \n",
"print 'probability of getting atleast four heads(i.e k=4,5 or 6) = ',Fraction(PA).limit_denominator(100)\n",
" \n",
"Pn=q**6 #probability of getting no heads\n",
"Pm=1-Pn#\n",
"print 'probability of getting one or more heads = ',Fraction(Pm).limit_denominator(100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.12 Pg 159"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A box contains 12 items of which three are defective\n",
"A sample of three items is selected from the box\n",
"number of elements in the sample space where samples are of size 3 220.0\n"
]
}
],
"source": [
"from scipy.misc import factorial\n",
"print \"A box contains 12 items of which three are defective\"\n",
"print \"A sample of three items is selected from the box\"\n",
"s=factorial(12)/(factorial(12-3)*factorial(3))# \n",
"print 'number of elements in the sample space where samples are of size 3',s\n",
"#X denotes the number of defective items in the sample\n",
"x=[0,1,2,3]# #range space of the random variable X"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.13 Pg 160"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"distribution table of X where first row gives the range space and second row gives the respective probabilities is as follows : \n",
"x(i)\t\t\tp(i)\n",
"2.0 \t\t\t1/36\n",
"3.0 \t\t\t1/18\n",
"4.0 \t\t\t1/12\n",
"5.0 \t\t\t1/9\n",
"6.0 \t\t\t5/36\n",
"7.0 \t\t\t1/6\n",
"8.0 \t\t\t5/36\n",
"9.0 \t\t\t1/9\n",
"10.0 \t\t\t1/12\n",
"11.0 \t\t\t1/18\n",
"12.0 \t\t\t1/36\n"
]
}
],
"source": [
"from numpy import mat,nditer\n",
"r=[1,2,3,4,5,6,5,4,3,2,1]\n",
"#number of outcomes whose sum is 2,3,4,5,6,7,8,9,10,11,12 respectively such that there is only 1 outcome i.e (1,1) whose sum is 2,two outcomes (1,2) and (2,1) whose sum is 3 and so on\n",
"t=36# #total number of elements in the sample space of the experiment of tossing a pair of dice\n",
"\n",
"\n",
"x=mat([[2,3,4,5,6,7,8,9,10,11,12]]) #range space of random variable X which assigns to each point in sample space the sum of the numbers \n",
"\n",
"D=mat([[2,3,4,5,6,7,8,9,10,11,12],[0.0277778, 0.0555556 , 0.0833333, 0.1111111, 0.1388889 ,0.1666667, 0.1388889 ,0.1111111, 0.0833333, 0.0555556, 0.0277778]])\n",
"print '\\n\\ndistribution table of X where first row gives the range space and second row gives the respective probabilities is as follows : '\n",
"\n",
"print \"x(i)\\t\\t\\tp(i)\"\n",
"for x,y in nditer([D[0,:],D[1,:]]):\n",
" y=float(y)\n",
" print x,\"\\t\\t\\t\",Fraction(y).limit_denominator(100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.14 Pg 160"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a box contains 12 items of which three are defective\n",
"A sample of three items is selected from the box\n",
"\n",
"distribution table for random variable X the upper row being values of X\n",
":\n",
"x(i)\t\t\tp(i)\n",
"0.0 \t\t\t21/55\n",
"1.0 \t\t\t27/55\n",
"2.0 \t\t\t7/57\n",
"3.0 \t\t\t0\n"
]
}
],
"source": [
"from fractions import Fraction\n",
"from numpy import nditer,mat\n",
"from scipy.misc import factorial\n",
"print \"a box contains 12 items of which three are defective\"\n",
"print \"A sample of three items is selected from the box\"\n",
"r=factorial(9)/(factorial(9-3)*factorial(3)) #number of samples of size 3 with no defective items\n",
"t=220# #number of different samples of size 3 i.e the number of elements in the sample space\n",
"P0=r/t #probability of getting no defective item\n",
"r1=3*(factorial(9)/(factorial(9-2)*factorial(2))) #number of samples of size 3 getting 1 defective item\n",
"P1=r1/t #probability of getting 1 defective item\n",
"r2=9*(factorial(3)/(factorial(3-2)*factorial(2))) #number of samples of size 3 getting 2 defective item\n",
"P2=r2/t #probability of getting 2 defective item\n",
"r3=1# #number of samples of size 3 getting 3 defective item\n",
"P3=r3/t #probability of getting 3 defective item\n",
"x=[0,1,2,3]#\n",
"p=mat([[P0,P1,P2,P3]])\n",
"D=mat([[0,1,2,3],[P0,P1,P2,P3]])\n",
"print '\\ndistribution table for random variable X the upper row being values of X\\n:'\n",
"\n",
"print \"x(i)\\t\\t\\tp(i)\"\n",
"for x,y in nditer([D[0,:],D[1,:]]):\n",
" y=float(y)\n",
" print x,\"\\t\\t\\t\",Fraction(y).limit_denominator(100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.15 Pg 161"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A fair coin is tossed six times\n",
"mean or expected number of heads are = 3.0\n",
"X is a random variable which gives possible number of defective items in a sample of size 3\n",
"expected number of defective items in a sample of size 3 are = 0.75\n",
"expected pay off for the race is = 4.5\n"
]
}
],
"source": [
"print \"A fair coin is tossed six times\"\n",
"x=[0,1,2,3,4,5,6] #number of heads which can occur\n",
"p=[1/64,6/64,15/64,20/64,15/64,6/64,1/64]# #probability of occurring of heads where 1/64 is probability for occurrence of a single head,6/64 that of occurrence of two heads and so on.\n",
"r=0#\n",
"for i in range(0,7):\n",
" r = r + (x[i]*p[i])#\n",
"\n",
"print 'mean or expected number of heads are = ',r\n",
" \n",
"print \"X is a random variable which gives possible number of defective items in a sample of size 3\"\n",
"#Box contains 12 items of which three are defective\n",
"x=[0,1,2,3]# #possible number of defective items in a smaple of size 3\n",
"p=[84/220,108/220,27/220,1/220]# #probability of occurrence of each number in x respectively where 84/220 is the probability for getting no defective item,108/220 is that of getting 1 defective item and so on.\n",
"r=0#\n",
"for i in range(0,4):\n",
" r = r + (x[i]*p[i])#\n",
"\n",
"print 'expected number of defective items in a sample of size 3 are = ',r\n",
" \n",
"Ph1=1/2# #probability of winning the race by first horse\n",
"Ph2=1/3# #probability of winning the race by second horse\n",
"Ph3=1/6# #probability of winning the race by third horse\n",
"#X is the payoff function for the winning horse\n",
"X1=2# #X pays $2 as first horse wins the rac\n",
"X2=6# #X pays $6 as second horse wins the race\n",
"X3=9# #X pays $9 as third horse wins the race\n",
"E=X1*Ph1+X2*Ph2+X3*Ph3\n",
"print 'expected pay off for the race is = ',E"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.16 Pg 162"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Variance of X is = 1.5\n",
"Standard deviation of X is = 1.2247\n",
"variance of X is = 0.4602\n",
"Standard deviation for X = 0.6784\n"
]
}
],
"source": [
"from numpy import sqrt\n",
"u=3 #mean of distribution of random variable X\n",
"x=[0,1,2,3,4,5,6] #values of X in the distribution as x where it is the number of times heads occurs when a coin is tossed six times\n",
"p=[1/64,6/64,15/64,20/64,15/64,6/64,1/64] #probabilities of occurrence of each value of X (x) in the distribution such that 1/64 gives the probability of occurrence of no heads at all,6/64 gives that of occurrence of heads for only one time and so on\n",
"k=0\n",
"for i in range(0,7):\n",
" k=k+((x[i]-u)**2)*p[i]\n",
"\n",
"print 'Variance of X is = ',k\n",
"s=sqrt(k)#\n",
"print'Standard deviation of X is = ',round(s,4)\n",
"\n",
"u=0.75# #mean \n",
"x=[0,1,2,3]# #values of random variable X as x in the probability distribution of X\n",
"p=[84/220,108/220,27/220,1/220]# #probability of values in x which appear in distribution table of X\n",
"g=0#\n",
"for i in range(0,4):\n",
" g=g+((x[i])**2)*p[i]\n",
"\n",
"h=g-(u*u) \n",
"print 'variance of X is = ',round(h,4)\n",
"sd=sqrt(h)#\n",
"print 'Standard deviation for X = ',round(sd,4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.17 Pg 162"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"expected number of times the man will hit the target = 20.0\n",
"Standard deviation = 4.0\n",
"expected number of correct answers in the exam = 2.5\n"
]
}
],
"source": [
"from __future__ import division\n",
"from numpy import sqrt\n",
"p=1/5# #probability of the man hitting a target\n",
"q=1-1/5# #probability of the man not hitting the target\n",
"n=100# #number of times the man fires\n",
"e=n*p# \n",
"print 'expected number of times the man will hit the target = ',e\n",
"r=sqrt(n*p*q)# \n",
"print 'Standard deviation = ',r\n",
"\n",
"p=1/2# #probability of guessing the correct answer in a five question true-false exam\n",
"n=5# #number of questions in the exam\n",
"g=n*p#\n",
"print 'expected number of correct answers in the exam = ',g"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.18 Pg 164"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"thus the probability that a value of X lies between 65 and 85 is atleast 0.75 according to Chebyshev inequality\n",
"thus the probability that a value of X lies between 60 and 90 is atleast 0.8888889 according to Chebyshev Inequality\n"
]
}
],
"source": [
"from __future__ import division\n",
"u=75# #mean of a random variable X\n",
"n=5# #standard deviation of X\n",
"k=2# #for k=2\n",
"l1=u-k*n\n",
"l2=u+k*n\n",
"P1=1-(1/k)**2\n",
"print \"thus the probability that a value of X lies between 65 and 85 is atleast 0.75 according to Chebyshev inequality\"\n",
"k=3# #for k=3\n",
"l1=u-k*n\n",
"l2=u+k*n\n",
"P2=1-(1/k)**2\n",
"print \"thus the probability that a value of X lies between 60 and 90 is atleast 0.8888889 according to Chebyshev Inequality\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ex7.19 Pg 166"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a die is tossed 5 times with the following outcomes\n",
"for a fair die the mean is 3.5.So law of large numbers tells us that as number of outcomes increase for this experiment,there is a greater likelihood that themean will get closer to 3.5\n"
]
}
],
"source": [
"from __future__ import division\n",
"print \"a die is tossed 5 times with the following outcomes\"\n",
"x1=3#\n",
"x2=4#\n",
"x3=6#\n",
"x4=1#\n",
"x5=4#\n",
"xmean=(x1+x2+x3+x4+x5)/5 #mean of the outcomes\n",
"print \"for a fair die the mean is 3.5.So law of large numbers tells us that as number of outcomes increase for this experiment,there is a greater likelihood that themean will get closer to 3.5\""
]
}
],
"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
}