summaryrefslogtreecommitdiff
path: root/Higher_Engineering_Mathematics_by_B._S._Grewal/chapter34.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Higher_Engineering_Mathematics_by_B._S._Grewal/chapter34.ipynb')
-rw-r--r--Higher_Engineering_Mathematics_by_B._S._Grewal/chapter34.ipynb1413
1 files changed, 1413 insertions, 0 deletions
diff --git a/Higher_Engineering_Mathematics_by_B._S._Grewal/chapter34.ipynb b/Higher_Engineering_Mathematics_by_B._S._Grewal/chapter34.ipynb
new file mode 100644
index 00000000..36e4482a
--- /dev/null
+++ b/Higher_Engineering_Mathematics_by_B._S._Grewal/chapter34.ipynb
@@ -0,0 +1,1413 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 34 : Probability And Distributions"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.1, page no. 830"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "From the principle of counting, the required no. of ways are 12∗11∗10∗9= \n",
+ "11880\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"From the principle of counting, the required no. of ways are 12∗11∗10∗9= \"\n",
+ "print 12*11*10*9"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.2.1, page no. 831"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "no. of permutations=9!/(2!∗2!∗2!)\n",
+ "45360\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "print \"no. of permutations=9!/(2!∗2!∗2!)\"\n",
+ "print math.factorial(9)/(math.factorial(2)*math.factorial(2)*math.factorial(2))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.2.2, page no. 831"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "no. of permutations=9!/(2!∗2!∗3!*3!)\n",
+ "2520\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "print \"no. of permutations=9!/(2!∗2!∗3!*3!)\"\n",
+ "print math.factorial(9)/(math.factorial(2)*math.factorial(2)*math.factorial(3)*math.factorial(3))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.3.1, page no. 832"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "no. of committees=C(6,3)∗C(5,2)=’\n",
+ "200\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"no. of committees=C(6,3)∗C(5,2)=’\"\n",
+ "print C(6,3)*C(5,2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.3.2, page no. 832"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "no. of committees=C(4,1)∗C(5,2)=’\n",
+ "40\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"no. of committees=C(4,1)∗C(5,2)=’\"\n",
+ "print C(4,1)*C(5,2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.3.3, page no. 833"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "no. of committees=C(6,3)∗C(4,2)=’\n",
+ "120\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"no. of committees=C(6,3)∗C(4,2)=’\"\n",
+ "print C(6,3)*C(4,2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.4.1, page no. 834"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The probability of getting a four is 1/6= 0.166666666667\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "print \"The probability of getting a four is 1/6= \",1./6"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.4.2, page no. 834"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The probability of getting an even no. 1/2= 0.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "print \"The probability of getting an even no. 1/2= \",1./2"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.5, page no. 835"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The probability of 53 Sundays is 2/7= 0.285714285714\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "print \"The probability of 53 Sundays is 2/7= \",2./7"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.6, page no. 835"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The five digits can be arranged in 5! ways = 120\n",
+ "Of which 4! will begin with 0 = 24\n",
+ "So, total no. of five digit numbers = 5!−4! = 96\n",
+ "The numbers ending in 04, 12, 20, 24, 32, 40 will be divisible by 4 \n",
+ "numbers ending in 04 = 3! = 6\n",
+ "numbers ending in 12 = 3!−2! = 4\n",
+ "numbers ending in 20 = 3! = 6\n",
+ "numbers ending in 24 = 3!−2! = 4\n",
+ "numbers ending in 32 = 3!−2! = 4\n",
+ "numbers ending in 40 = 3! = 6\n",
+ "So, total no. of favourable ways = 6+4+6+4+4+6 = 30\n",
+ "probability = 30/96 = 0.3125\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "print \"The five digits can be arranged in 5! ways = \",math.factorial(5)\n",
+ "print \"Of which 4! will begin with 0 = \",math.factorial(4)\n",
+ "print \"So, total no. of five digit numbers = 5!−4! = \",math.factorial(5)-math.factorial(4)\n",
+ "print \"The numbers ending in 04, 12, 20, 24, 32, 40 will be divisible by 4 \"\n",
+ "print \"numbers ending in 04 = 3! = \",math.factorial(3)\n",
+ "print \"numbers ending in 12 = 3!−2! = \",math.factorial(3)-math.factorial(2)\n",
+ "print \"numbers ending in 20 = 3! = \",math.factorial(3)\n",
+ "print \"numbers ending in 24 = 3!−2! = \",math.factorial(3)-math.factorial(2)\n",
+ "print \"numbers ending in 32 = 3!−2! = \",math.factorial(3)-math.factorial(2)\n",
+ "print \"numbers ending in 40 = 3! = \",math.factorial(3)\n",
+ "print \"So, total no. of favourable ways = 6+4+6+4+4+6 = \",6+4+6+4+4+6\n",
+ "print \"probability = 30/96 = \",30./96"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.7, page no. 836"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total no. of possible cases = C(40,4) = 91390\n",
+ "Favourable outcomes = C(24,2)∗C(15,1) = 4140\n",
+ "Probability = 0.0453003610898\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Total no. of possible cases = C(40,4) = \",C(40,4)\n",
+ "print \"Favourable outcomes = C(24,2)∗C(15,1) = \",C(24,2)*C(15,1)\n",
+ "print \"Probability = \",float(C(24,2)*C(15,1))/C(40,4)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.8, page no. 836"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total no. of possible cases = C(15,8) = 6435\n",
+ "Favourable outcomes = C(5,2)∗C(10,6) = 2100\n",
+ "Probability = 0.32634032634\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Total no. of possible cases = C(15,8) = \",C(15,8)\n",
+ "print \"Favourable outcomes = C(5,2)∗C(10,6) = \",C(5,2)*C(10,6)\n",
+ "print \"Probability = \",float(C(5,2)*C(10,6))/C(15,8)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.9.1, page no. 837"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total no. of possible cases = C(9,3) = 84\n",
+ "Favourable outcomes = C(2,1)∗C(3,1)*C(4,1) = 24\n",
+ "Probability = 0.285714285714\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Total no. of possible cases = C(9,3) = \",C(9,3)\n",
+ "print \"Favourable outcomes = C(2,1)∗C(3,1)*C(4,1) = \",C(2,1)*C(3,1)*C(4,1)\n",
+ "print \"Probability = \",float(C(2,1)*C(3,1)*C(4,1))/C(9,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.9.2, page no. 837"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total no. of possible cases = C(9,3) = 84\n",
+ "Favourable outcomes = C(2,2)∗C(7,1)+C(3,2)∗C(6,1)+C(4,2)∗C(5,1) = 55\n",
+ "Probability = 0.654761904762\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Total no. of possible cases = C(9,3) = \",C(9,3)\n",
+ "print \"Favourable outcomes = C(2,2)∗C(7,1)+C(3,2)∗C(6,1)+C(4,2)∗C(5,1) = \",C(2,2)*C(7,1)+C(3,2)*C(6,1)+C(4,2)*C(5,1)\n",
+ "print \"Probability = \",float(C(2,2)*C(7,1)+C(3,2)*C(6,1)+C(4,2)*C(5,1))/C(9,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.9.3, page no. 838"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total no. of possible cases = C(9,3) = 84\n",
+ "Favourable outcomes = C(3,3)+C(4,3) = 5\n",
+ "Probability = 0.0595238095238\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Total no. of possible cases = C(9,3) = \",C(9,3)\n",
+ "print \"Favourable outcomes = C(3,3)+C(4,3) = \",C(3,3)+C(4,3)\n",
+ "print \"Probability = \",5./84"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.13, page no. 840"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of drawing an ace or spade or both from pack of 52 cards = 4/52+13/52−1/52= 17\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of drawing an ace or spade or both from pack of 52 cards = 4/52+13/52−1/52= \",4+13-1/52"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.14.1, page no. 841"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of first card being a king = 4/52 = 0.0769230769231\n",
+ "Probability of second card being a queen = 4/52 = 0.0769230769231\n",
+ "Probability of drawing both cards in succession = 4/52∗4/52= 0.00591715976331\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of first card being a king = 4/52 = \",4./52\n",
+ "print \"Probability of second card being a queen = 4/52 = \",4./52\n",
+ "print \"Probability of drawing both cards in succession = 4/52∗4/52= \",(4./52)*(4./52)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.15.1, page no. 842"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of getting 7 in first toss and not getting it in second toss = 1/6∗5/6 = 0.138888888889\n",
+ "Probability of not getting 7 in first toss and getting it in second toss = 5/6∗1/6 = 0.138888888889\n",
+ "Required probability = 1/6∗5/6+5/6∗1/6 = 0.277777777778\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of getting 7 in first toss and not getting it in second toss = 1/6∗5/6 = \",(1./6)*(5./6)\n",
+ "print \"Probability of not getting 7 in first toss and getting it in second toss = 5/6∗1/6 = \",(5./6)*(1./6)\n",
+ "print \"Required probability = 1/6∗5/6+5/6∗1/6 = \",((1./6)*(5./6))+((5./6)*(1./6))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.15.2, page no. 842"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of not getting 7 in either toss = 5/6∗5/6 = 0.694444444444\n",
+ "Probability of getting 7 at least once = 1−5/6∗5/6 = 0.305555555556\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of not getting 7 in either toss = 5/6∗5/6 = \",(5./6)*(5./6)\n",
+ "print \"Probability of getting 7 at least once = 1−5/6∗5/6 = \",1-(5./6)*(5./6)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.15.3, page no. 842"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of getting 7 twice = 1/6∗1/6 = 0.0277777777778\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of getting 7 twice = 1/6∗1/6 = \",(1./6)*(1./6)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.16, page no. 843"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of engineering subject being choosen = (1/3∗3/8)+(2/3∗5/8) = 0.541666666667\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of engineering subject being choosen = (1/3∗3/8)+(2/3∗5/8) = \",((1./3)*(3./8)) +((2./3)*(5./8))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.17, page no. 844"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of white ball being choosen = 2/6∗6/13+4/6∗5/13 = 0.410256410256\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of white ball being choosen = 2/6∗6/13+4/6∗5/13 = \",((2./6)*(6./13))+((4./6)*(5./13))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.18, page no. 844"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Chances of winning of A=1/2+(1/2)ˆ2∗(1/2)+(1/2)ˆ4∗(1/2)+(1/2)ˆ6∗(1/2)+..= 0.666666666667\n",
+ "Chances of winning of B=1−chances of winning of A = 1\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Chances of winning of A=1/2+(1/2)ˆ2∗(1/2)+(1/2)ˆ4∗(1/2)+(1/2)ˆ6∗(1/2)+..= \",(1./2)/(1-(1./2)**2)\n",
+ "print \"Chances of winning of B=1−chances of winning of A = \",1-(2/3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.19.1, page no. 845"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total no. of possible outcomes = C(10,2) = 45\n",
+ "Favourable outcomes = 5*5 = 25\n",
+ "P = 0.555555555556\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Total no. of possible outcomes = C(10,2) = \",C(10,2)\n",
+ "print \"Favourable outcomes = 5*5 = \",5*5\n",
+ "print \"P = \",25./45"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.19.2, page no. 845"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total no. of possible outcomes = 10*10 = 100\n",
+ "Favourable outcomes = 5*5+5*5 = 50\n",
+ "P = 0.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Total no. of possible outcomes = 10*10 = \",10*10\n",
+ "print \"Favourable outcomes = 5*5+5*5 = \",5*5+5*5\n",
+ "print \"P = \",50./100"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.20, page no. 846"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of A/B = AandB/B = 0.25\n",
+ "Probability of B/A = AandB/A = 0.333333333333\n",
+ "Probability of AandBnot = A−AandB = 0.166666666667\n",
+ "Probability of A/Bnot = AandBnot/Bnot = 0.25\n"
+ ]
+ }
+ ],
+ "source": [
+ "A = 1./4\n",
+ "B = 1./3\n",
+ "AorB = 1./2\n",
+ "AandB = A+B-AorB\n",
+ "print \"Probability of A/B = AandB/B = \",AandB/B\n",
+ "print \"Probability of B/A = AandB/A = \",AandB/A\n",
+ "print \"Probability of AandBnot = A−AandB = \",A-AandB\n",
+ "print \"Probability of A/Bnot = AandBnot/Bnot = \",(1./6)/(1-1./3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.22, page no. 846"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of A hitting target = 3/5\n",
+ "Probability of B hitting target = 2/5\n",
+ "Probability of C hitting target = 3/4\n",
+ "Probability that two shots hit = 3/5∗2/5∗(1−3/4)+2/5∗3/4∗(1−3/5)+3/4∗3/5∗(1−2/5) = \n",
+ "0.45\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of A hitting target = 3/5\"\n",
+ "print \"Probability of B hitting target = 2/5\"\n",
+ "print \"Probability of C hitting target = 3/4\"\n",
+ "print \"Probability that two shots hit = 3/5∗2/5∗(1−3/4)+2/5∗3/4∗(1−3/5)+3/4∗3/5∗(1−2/5) = \"\n",
+ "print (3./5)*(2./5)*(1-3./4)+(2./5)*(3./4)*(1-3./5)+(3./4)*(3./5)*(1-2./5)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.23, page no. 847"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of problem not getting solved = 1/2∗2/3∗3/4 = 0.25\n",
+ "Probability of problem getting solved = 1−(1/2∗2/3∗3/4) = 0.75\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability of problem not getting solved = 1/2∗2/3∗3/4 = \",(1./2)*(2./3)*(3./4)\n",
+ "print \"Probability of problem getting solved = 1−(1/2∗2/3∗3/4) = \",1-((1./2)*(2./3)*(3./4))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.25, page no. 848"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total frequency=integrate(f,x,0,2) =\n",
+ "u1 about origin = 1\n",
+ "u2 about origin = 16/15\n",
+ "Standard deviation = (u2−u1ˆ2)ˆ0.5= 0.258198889747161\n",
+ "Mean deviation about the mean = (1/n)∗(integrate(|x−1|∗(xˆ3),x,0,1)+integrate(|x−1|∗((2−x)ˆ3),x,1,2))\n",
+ "1/5\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy\n",
+ "\n",
+ "print \"Total frequency=integrate(f,x,0,2) =\" \n",
+ "n = sympy.integrate('x**3',('x',0,1))+sympy.integrate('(2-x)**3',('x',1,2))\n",
+ "print \"u1 about origin = \",\n",
+ "u1 = (1/n)*(sympy.integrate('(x)*(x**3)',('x',0,1))+sympy.integrate('(x)*((2-x)**3)',('x',1,2)))\n",
+ "print u1\n",
+ "print \"u2 about origin = \",\n",
+ "u2 = (1/n)*(sympy.integrate('(x**2)*(x**3)',('x',0,1))+sympy.integrate('(x**2)*((2-x)**3)',('x',1,2)))\n",
+ "print u2\n",
+ "print \"Standard deviation = (u2−u1ˆ2)ˆ0.5= \",(u2-u1**2)**0.5\n",
+ "print \"Mean deviation about the mean = (1/n)∗(integrate(|x−1|∗(xˆ3),x,0,1)+integrate(|x−1|∗((2−x)ˆ3),x,1,2))\"\n",
+ "print (1/n)*(sympy.integrate('(1-x)*(x**3)',('x',0,1))+sympy.integrate('(x-1)*((2-x)**3)',('x',1,2)))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.26, page no. 849"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 47,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability = (0.45∗0.03)/(0.45∗0.03+0.25∗0.05+0.3∗0.04 = 0.355263157895\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability = (0.45∗0.03)/(0.45∗0.03+0.25∗0.05+0.3∗0.04 = \",(0.45*0.03)/(0.45*0.03+0.25*0.05+0.3*0.04)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.27, page no. 849"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability = (1/3∗2/6∗3/5)/(1/3∗2/6∗3/5+1/3∗1/6∗2/5+1/3∗3/6∗1/5) = 1.05555555556\n"
+ ]
+ }
+ ],
+ "source": [
+ "print \"Probability = (1/3∗2/6∗3/5)/(1/3∗2/6∗3/5+1/3∗1/6∗2/5+1/3∗3/6∗1/5) = \",\n",
+ "print ((1./3)*(2./6)*(3./5))/((1./3)*(2./6)*(3./5))+((1./3)*(1./6)*(2./5))+((1./3)*(3./6)*(1./5))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.28, page no. 850"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of no success = 8/27 \n",
+ "Probability of a success = 1/3 \n",
+ "Probability of one success = 4/9\n",
+ "Probability of two success = 2/9\n",
+ "Probability of three success = 2/9\n",
+ "mean=sum of i∗pi = 1.0\n",
+ "sum of i∗piˆ2 = 1.66666666667\n",
+ "variance = (sum of i∗piˆ2)−1= 0.666666666667\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy\n",
+ "\n",
+ "print \"Probability of no success = 8/27 \"\n",
+ "print \"Probability of a success = 1/3 \"\n",
+ "print \"Probability of one success = 4/9\"\n",
+ "print \"Probability of two success = 2/9\"\n",
+ "print \"Probability of three success = 2/9\"\n",
+ "A = numpy.array([[0,1,2,3],[8./27,4./9,2./9,1./27]])\n",
+ "print \"mean=sum of i∗pi = \",\n",
+ "print A[0,0]*A[1,0]+A[0,1]*A[1,1]+A[0,3]*A[1,3]+A[0,2]*A[1,2]\n",
+ "print \"sum of i∗piˆ2 = \",\n",
+ "print A[0,0]**2*A[1,0]+A[0,1]**2*A[1,1]+A[0,3]**2*A[1,3]+A[0,2]**2*A[1,2]\n",
+ "print \"variance = (sum of i∗piˆ2)−1= \",\n",
+ "print A[0,0]**2*A[1,0]+A[0,1]**2*A[1,1]+A[0,3]**2*A[1,3]+A[0,2]**2*A[1,2]-1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.29, page no. 851"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 53,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Sumof all pi = 1 \n",
+ "Hence ,\n",
+ "p(x<4) = 16.0*k\n",
+ "p(x>=5) = 24.0*k\n",
+ "p(3<x<=6) = 33.0*k\n",
+ "p(x<=2) = 9.0*k\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy,numpy\n",
+ "\n",
+ "k = sympy.Symbol('k')\n",
+ "A =numpy.array([[0,1,2,3,4,5,6],[k,3*k,5*k,7*k,9*k,11*k,13*k]])\n",
+ "print \"Sumof all pi = 1 \"\n",
+ "print \"Hence ,\"\n",
+ "k = 1./49\n",
+ "print \"p(x<4) = \",\n",
+ "a = A[1,0]+A[1,1]+A[1,3]+A[1,2]\n",
+ "print a.evalf()\n",
+ "print \"p(x>=5) = \",\n",
+ "b = A[1,5]+A[1,6]\n",
+ "print b.evalf()\n",
+ "print \"p(3<x<=6) = \",\n",
+ "c = A[1,4]+A[1,5]+A[1,6]\n",
+ "print c.evalf()\n",
+ "print \"p(x<=2) = \",\n",
+ "e = A[1,0]+A[1,1]+A[1,2]\n",
+ "print e.evalf()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.30, page no. 853"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 57,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Sum of all pi = 1\n",
+ "Hence,\n",
+ "p(x<6) = 2.0*k**2 + 10.0*k\n",
+ "p(x>=6) = 9.0*k**2 + k\n",
+ "p(3<x<5) = 8.0*k\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy,numpy,math\n",
+ "\n",
+ "k = sympy.Symbol('k')\n",
+ "A =numpy.array([[0,1,2,3,4,5,6,7],[0,k,2*k,2*k,3*k,k**2,2*k**2,7*k**2+ k]])\n",
+ "print \"Sum of all pi = 1\"\n",
+ "print \"Hence,\"\n",
+ "k = 1./10\n",
+ "print \"p(x<6) = \",\n",
+ "a = A[1,0]+A[1,1]+A[1,3]+A[1,2]+ A[1,3]+A[1,4]+A[1,6]\n",
+ "print a.evalf()\n",
+ "print \"p(x>=6) = \",\n",
+ "b = A[1,6]+A[1,7]\n",
+ "print b.evalf()\n",
+ "print \"p(3<x<5) = \",\n",
+ "c = A[1,1]+A[1,2]+A[1,3]+A[1,4]\n",
+ "print c.evalf()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.31, page no. 853"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 62,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Clearly, f>0 for every x in (1,2) and integrate(f,x,0,numpy.inf)= 1.00000000000000\n",
+ "Required probability=p(1<=x<=2)= integrate(f,x,1,2) = 0.232544157934830\n",
+ "Cumulative probability function f(2)=integrate(f,x,−%inf,2) = 0.864664716763387\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy,numpy,math\n",
+ "y = sympy.Symbol('y')\n",
+ "f = math.e**(-y)\n",
+ "print \"Clearly, f>0 for every x in (1,2) and integrate(f,x,0,numpy.inf)= \",\n",
+ "print sympy.integrate(math.e**(-y),('y',0,sympy.oo))\n",
+ "print \"Required probability=p(1<=x<=2)= integrate(f,x,1,2) = \",\n",
+ "print sympy.integrate(math.e**(-y),('y',1,2))\n",
+ "print \"Cumulative probability function f(2)=integrate(f,x,−%inf,2) = \",\n",
+ "print sympy.integrate(math.e**(-y),('y',0,2))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.33, page no. 854"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 65,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total probability = integrate(f,x,0,6)=\n",
+ "2*k\n",
+ "4*k\n",
+ "2*k\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy\n",
+ "\n",
+ "k = sympy.Symbol('k')\n",
+ "print \"Total probability = integrate(f,x,0,6)=\"\n",
+ "p = sympy.integrate('k*x',('x',0,2))\n",
+ "q = sympy.integrate('2*k',('x',2,4))\n",
+ "r = sympy.integrate('-k*x+6*k',('x',4,6))\n",
+ "print p\n",
+ "print q\n",
+ "print r"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "collapsed": true
+ },
+ "source": [
+ "## Example 34.34, page no. 854"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "First row of A displays the value of x\n",
+ "The second row of x displays the probability of corresponding to x\n",
+ "E(x) = 5.5\n",
+ "E(x)ˆ2 = 46.5\n",
+ "E(2∗x+1)^2=E(4∗xˆ2+4∗x+1) = 209.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy\n",
+ "\n",
+ "A = numpy.array([[-3.,6.,9.],[1./6,1./2,1./3]])\n",
+ "print \"First row of A displays the value of x\"\n",
+ "print \"The second row of x displays the probability of corresponding to x\"\n",
+ "print \"E(x) = \",\n",
+ "c = A[0,0]*A[1,0]+A[0,1]*A[1,1]+A[0,2]*A[1,2]\n",
+ "print c\n",
+ "print \"E(x)ˆ2 = \",\n",
+ "b = A[0,0]**2*A[1,0]+A[0,1]**2*A[1,1]+A[0,2]**2*A[1,2]\n",
+ "print b\n",
+ "print \"E(2∗x+1)^2=E(4∗xˆ2+4∗x+1) = \",4*b+4*c+1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.35, page no. 855"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Total frequency=integrate(f,x,0,2)= \n",
+ "u1 about origin = \n",
+ "u2 about origin = \n",
+ "standard deviation = (u2−u1ˆ2)ˆ0.5 = 0.258198889747161\n",
+ "Mean deviation about the mean = (1/n)∗(integrate|x−1|∗(xˆ3),x,0,1)+integrate(|x−1|∗((2−x)ˆ3),x,1,2))\n",
+ "1/5\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy\n",
+ "\n",
+ "print \"Total frequency=integrate(f,x,0,2)= \"\n",
+ "n = sympy.integrate('x**3',('x',0,1))+sympy.integrate('(2-x)**3',('x',1,2))\n",
+ "print \"u1 about origin = \"\n",
+ "u1 = (1/n)*(sympy.integrate('(x)*(x**3)',('x',0,1))+sympy.integrate('(x)*((2-x)**3)',('x',1,2)))\n",
+ "print \"u2 about origin = \"\n",
+ "u2 = (1/n)*(sympy.integrate('(x**2)*(x**3)',('x',0,1))+sympy.integrate('(x**2)*((2-x)**3)',('x',1,2)))\n",
+ "print \"standard deviation = (u2−u1ˆ2)ˆ0.5 = \",(u2-u1**2)**0.5\n",
+ "print \"Mean deviation about the mean = (1/n)∗(integrate|x−1|∗(xˆ3),x,0,1)+integrate(|x−1|∗((2−x)ˆ3),x,1,2))\"\n",
+ "print (1/n)*(sympy.integrate('(1-x)*(x**3)',('x',0,1))+sympy.integrate('(x-1)*((2-x)**3)',('x',1,2)))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.38, page no. 857"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Probability that exactly two will be defective = C(12,2)∗(0.1)ˆ2∗(0.9)ˆ10 = 0.230127770466\n",
+ "Probability that at least two will be defective = 1−(C(12,0)∗(0.9)ˆ12+C(12,1)∗(0.1)∗(0.9)ˆ11) = 0.340997748211\n",
+ "The probability that none will be defective = C(12,12)∗(0.9)ˆ12 = 0.282429536481\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Probability that exactly two will be defective = C(12,2)∗(0.1)ˆ2∗(0.9)ˆ10 = \",C(12,2)*(0.1)**2*(0.9)**10\n",
+ "print \"Probability that at least two will be defective = 1−(C(12,0)∗(0.9)ˆ12+C(12,1)∗(0.1)∗(0.9)ˆ11) = \",\n",
+ "print 1-(C(12,0)*(0.9)**12+C(12,1)*(0.1)*(0.9)**11)\n",
+ "print \"The probability that none will be defective = C(12,12)∗(0.9)ˆ12 = \",C(12,12)*(0.9)**12"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.39, page no. 858"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of 8 heads and 4 tail sin 12 trials = p(8) = C(12,8)∗(1/2)ˆ8∗(1/2)ˆ4= 0.120849609375\n",
+ "The expected no. of such cases in 256 sets = 256∗p(8) = 30.9375\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Probability of 8 heads and 4 tail sin 12 trials = p(8) = C(12,8)∗(1/2)ˆ8∗(1/2)ˆ4= \",C(12.,8.)*(1./2)**8*(1./2)**4\n",
+ "print \"The expected no. of such cases in 256 sets = 256∗p(8) = \",256*(495./4096)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34.40, page no. 859"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Probability of a defective part = 2/20 =0.1 \n",
+ "Probability of a non defective part = 0.9 \n",
+ "Probabaility of atleast three defectives in a sample = 0.323073194811\n",
+ "No. of sample shaving three defective parts = 1000∗0.323 = 323.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "def C(a,b):\n",
+ " x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))\n",
+ " return x\n",
+ "print \"Probability of a defective part = 2/20 =0.1 \"\n",
+ "print \"Probability of a non defective part = 0.9 \"\n",
+ "print \"Probabaility of atleast three defectives in a sample = \",\n",
+ "print 1-(C(20.,0.)*(0.9)**20+C(20.,1.)*(0.1)*(0.9)**19+C(20.,2.)*(0.1)**2*(0.9)**18)\n",
+ "print \"No. of sample shaving three defective parts = 1000∗0.323 = \",1000*0.323"
+ ]
+ }
+ ],
+ "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.10"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}