summaryrefslogtreecommitdiff
path: root/Higher_Engineering_Mathematics_by_B._S._Grewal/chapter35_1.ipynb
blob: 5ca46e4eb7ffb2ccd410e9cdc53ca5654bae86fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 35 : Sampling And Inference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.1, page no. 864"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Suppose the coin is unbiased\n",
      "Then probability of getting the head in a toss = 1/2 \n",
      "Then, expected no. of successes = a = 1/2∗400\n",
      "Observed no. of successes = 216\n",
      "The excess of observed value over expected value =  216\n",
      "S. D. of simple sampling = (n∗p∗q)ˆ0.5 = c \n",
      "Hence, z = (b−a)/c =  21.6\n",
      "As z<1.96, the hypothesis is accepted at 5% level of significance\n"
     ]
    }
   ],
   "source": [
    "print \"Suppose the coin is unbiased\"\n",
    "print \"Then probability of getting the head in a toss = 1/2 \"\n",
    "print \"Then, expected no. of successes = a = 1/2∗400\"\n",
    "a = 1/2*400\n",
    "print \"Observed no. of successes = 216\"\n",
    "b = 216\n",
    "print \"The excess of observed value over expected value = \",b-a\n",
    "print \"S. D. of simple sampling = (n∗p∗q)ˆ0.5 = c \"\n",
    "c = (400*0.5*0.5)**0.5\n",
    "print \"Hence, z = (b−a)/c = \",(b-a)/c\n",
    "print \"As z<1.96, the hypothesis is accepted at 5% level of significance\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.2, page no. 865"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Suppose the die is unbiased \n",
      "Then probability of getting 5 or 6 with one die=1/3 \n",
      "Then, expected no. of successes = a = 1/3∗9000 \n",
      "Observed no. of successes = 3240\n",
      "The excess of observed value over expected value =  240.0\n",
      "S. D. of simple sampling = (n∗p∗q)ˆ0.5=c\n",
      "Hence, z = (b−a)/c =  5.366563146\n",
      "As z>2.58, the hypothesis has to be rejected at 1% level of significance\n"
     ]
    }
   ],
   "source": [
    "print \"Suppose the die is unbiased \"\n",
    "print \"Then probability of getting 5 or 6 with one die=1/3 \"\n",
    "print \"Then, expected no. of successes = a = 1/3∗9000 \"\n",
    "a = 1./3*9000\n",
    "print \"Observed no. of successes = 3240\"\n",
    "b = 3240\n",
    "print \"The excess of observed value over expected value = \",b-a\n",
    "print \"S. D. of simple sampling = (n∗p∗q)ˆ0.5=c\"\n",
    "c = (9000*(1./3)*(2./3))**0.5\n",
    "print \"Hence, z = (b−a)/c = \",(b-a)/c\n",
    "print \"As z>2.58, the hypothesis has to be rejected at 1% level of significance\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.3, page no. 865"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "q = 1−p \n",
      "Standard error of the population of families having a monthly income of rs. 250 or less=(p∗q/n)ˆ0.5 =  0.0148442858929\n",
      "Hence taking 103/420 to be the estimate of families having a monthly income of rs. 250 or less, the limits are 20% and 29% approximately\n"
     ]
    }
   ],
   "source": [
    "p = 206./840\n",
    "print \"q = 1−p \"\n",
    "q = 1-p\n",
    "n = 840\n",
    "print \"Standard error of the population of families having a monthly income of rs. 250 or less=(p∗q/n)ˆ0.5 = \",(p*q/n)**0.5\n",
    "print \"Hence taking 103/420 to be the estimate of families having a monthly income of rs. 250 or less, the limits are 20% and 29% approximately\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.4, page no. 866"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p=(n1∗p1+n2∗p2)/(n1+n2)\n",
      "0.1904\n",
      "q = 1−p \n",
      "0.8096\n",
      "e=(p∗q∗(1/n1+1/n2))ˆ0.5\n",
      "0.0163590274093\n",
      "z =  0.916924926202\n",
      "As z<1, the difference between the proportions is not significant. \n"
     ]
    }
   ],
   "source": [
    "n1 = 900\n",
    "n2 = 1600\n",
    "p1 = 20./100\n",
    "p2 = 18.5/100\n",
    "print \"p=(n1∗p1+n2∗p2)/(n1+n2)\"\n",
    "p = (n1*p1+n2*p2)/(n1+n2)\n",
    "print p\n",
    "print \"q = 1−p \"\n",
    "q = 1-p\n",
    "print q\n",
    "print \"e=(p∗q∗(1/n1+1/n2))ˆ0.5\"\n",
    "e = (p*q*((1./n1)+(1./n2)))**0.5\n",
    "print e\n",
    "z = (p1-p2)/e\n",
    "print \"z = \",z\n",
    "print \"As z<1, the difference between the proportions is not significant. \""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.5, page no. 867"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "q1 = 1−p1 \n",
      "q2=1−p2\n",
      "e=((p1∗q1/n1)+(p2*q2/n2))ˆ0.5\n",
      "Hence, it is likely that real difference will be hidden.\n"
     ]
    }
   ],
   "source": [
    "p1 = 0.3\n",
    "p2 = 0.25\n",
    "print \"q1 = 1−p1 \"\n",
    "q1 = 1-p1\n",
    "print \"q2=1−p2\"\n",
    "q2 = 1-p2\n",
    "n1 = 1200\n",
    "n2 = 900\n",
    "print \"e=((p1∗q1/n1)+(p2*q2/n2))ˆ0.5\"\n",
    "e = ((p1*q1/n1)+(p2*q2/n2))**0.5\n",
    "z = (p1-p2)/e\n",
    "print \"Hence, it is likely that real difference will be hidden.\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.6, page no. 868"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "m and n represents mean and number of objects in sample respectively \n",
      "z=(m−M)/(d/(nˆ0.5)\n",
      "z =  2.7950310559\n",
      "As z>1.96, it cannot be regarded as a random sample\n"
     ]
    }
   ],
   "source": [
    "print \"m and n represents mean and number of objects in sample respectively \"\n",
    "m = 3.4\n",
    "n = 900.\n",
    "M = 3.25\n",
    "d = 1.61\n",
    "print \"z=(m−M)/(d/(nˆ0.5)\"\n",
    "z = (m-M)/(d/(n**0.5))\n",
    "print \"z = \",z\n",
    "print \"As z>1.96, it cannot be regarded as a random sample\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.9, page no. 871"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "m1 and n1 represents mean and no. of objects in sample 1\n",
      "m2 and n2 represents mean and no. of objects in sample 2\n",
      "On the hypothesis that the samples are drawn from the same population of d = 2.5, we get\n",
      "z =  -5.16397779494\n",
      "Since |z|>1.96, thus samples cannot be regarded as drawn from the same population\n"
     ]
    }
   ],
   "source": [
    "print \"m1 and n1 represents mean and no. of objects in sample 1\"\n",
    "print \"m2 and n2 represents mean and no. of objects in sample 2\"\n",
    "m1 = 67.5\n",
    "m2 = 68.\n",
    "n1 = 1000.\n",
    "n2 = 2000.\n",
    "d = 2.5\n",
    "print \"On the hypothesis that the samples are drawn from the same population of d = 2.5, we get\"\n",
    "z = (m1-m2)/(d*((1/n1)+(1/n2))**0.5)\n",
    "print \"z = \",z\n",
    "print \"Since |z|>1.96, thus samples cannot be regarded as drawn from the same population\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.10, page no. 872"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "m1, d1 and n1 denotes mean, deviation and no.of objects in first sample \n",
      "m2, d2 and n2 denotes mean, deviation and no.of objects in second sample\n",
      "S. E. of the difference of the mean heights is  0.0703246933872\n",
      "-0.7\n",
      "|m1−m2|>10e, this is highly significant. hence, the data indicates that the sailors are on the average taller than the soldiers.\n"
     ]
    }
   ],
   "source": [
    "print \"m1, d1 and n1 denotes mean, deviation and no.of objects in first sample \"\n",
    "m1 = 67.85\n",
    "d1 = 2.56\n",
    "n1 = 6400.\n",
    "print \"m2, d2 and n2 denotes mean, deviation and no.of objects in second sample\"\n",
    "m2 = 68.55\n",
    "d2 = 2.52\n",
    "n2 = 1600.\n",
    "print \"S. E. of the difference of the mean heights is \",\n",
    "e = ((d**2/n1)+(d2**2/n2))**0.5\n",
    "print e\n",
    "print m1-m2\n",
    "print \"|m1−m2|>10e, this is highly significant. hence, the data indicates that the sailors are on the average taller than the soldiers.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.12, page no. 874"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First of row denotes the different values of sample \n",
      "The second row denotes the corresponding deviation\n",
      "The third row denotes the corresponding square of deviation\n",
      "The sum of second row elements =  10.0\n",
      "The sum of third row elements =  66.0\n",
      "let m be the mean \n",
      "let d be the standard deviation\n",
      "1.84522581263\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros((3,9))\n",
    "n = 9\n",
    "print \"First of row denotes the different values of sample \"\n",
    "A[0,:] = [45,47,50,52,48,47,49,53,51]\n",
    "print \"The second row denotes the corresponding deviation\"\n",
    "for i in range(0,9):\n",
    "    A[1,i] = A[0,i]-48\n",
    "print \"The third row denotes the corresponding square of deviation\"\n",
    "for i in range(0,9):\n",
    "    A[2,i] = A[1,i]**2\n",
    "print \"The sum of second row elements = \",\n",
    "a  =0\n",
    "for i in range(0,9):\n",
    "    a = a+A[1,i]\n",
    "print a\n",
    "print \"The sum of third row elements = \",\n",
    "b = 0\n",
    "for i in range(0,9):\n",
    "    b = b+A[2,i]\n",
    "print b\n",
    "print \"let m be the mean \"\n",
    "m = 48+a/n\n",
    "print \"let d be the standard deviation\"\n",
    "d = ((b/n)-(a/n)**2)**0.5\n",
    "t = (m-47.5)*(n-1)**0.5/d\n",
    "print t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 35.13, page no. 876"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d and n represents the deviation and no. objects in given sample\n",
      "Taking the hypothesis that the product is not inferior i.e. there is no significant difference between m and M\n",
      "3.15\n",
      "Degrees of freedom= \n",
      "9.0\n"
     ]
    }
   ],
   "source": [
    "print \"d and n represents the deviation and no. objects in given sample\"\n",
    "n = 10.\n",
    "d = 0.04\n",
    "m = 0.742\n",
    "M = 0.700\n",
    "print \"Taking the hypothesis that the product is not inferior i.e. there is no significant difference between m and M\"\n",
    "t = (m-M)*(n-1)**0.5/d\n",
    "print t\n",
    "print \"Degrees of freedom= \"\n",
    "f = n-1\n",
    "print f"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 34.15, page no. 878"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row denotes the boy no. \n",
      "The second row denotes the marks in test I(x1)\n",
      "The third row denotes the marks in test I(x2)\n",
      "The fourth row denotes the difference of marks in two tests(d)\n",
      "The fifth row denotes the (d−1)\n",
      "The sixth row denotes the square of elements of fourth row \n",
      "[[  1.   2.   3.   4.   5.   6.   7.   8.   9.  10.  11.]\n",
      " [ 23.  20.  19.  21.  18.  20.  18.  17.  23.  16.  19.]\n",
      " [ 24.  19.  22.  18.  20.  22.  20.  20.  23.  20.  17.]\n",
      " [  1.  -1.   3.  -3.   2.   2.   2.   3.   0.   4.  -2.]\n",
      " [  0.  -2.   2.  -4.   1.   1.   1.   2.  -1.   3.  -3.]\n",
      " [  1.   1.   9.   9.   4.   4.   4.   9.   0.  16.   4.]]\n",
      "The sum of elements of fourth row=\n",
      "11.0\n",
      "The sum of elements of sixth row= \n",
      "61.0\n",
      "Standard deviation\n",
      "d =  2.46981780705\n",
      "t =  1.48063606712\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros((6,11))\n",
    "n = 11\n",
    "print \"The first row denotes the boy no. \"\n",
    "A[0,:] = [1,2,3,4,5,6,7,8,9,10,11]\n",
    "print \"The second row denotes the marks in test I(x1)\"\n",
    "A[1,:] = [23,20,19,21,18,20,18,17,23,16,19]\n",
    "print \"The third row denotes the marks in test I(x2)\"\n",
    "A[2,:] = [24,19,22,18,20,22,20,20,23,20,17]\n",
    "print \"The fourth row denotes the difference of marks in two tests(d)\"\n",
    "for i in range (0,11):\n",
    "    A[3,i] = A[2,i]-A[1,i]\n",
    "print \"The fifth row denotes the (d−1)\"\n",
    "for i in range (0,11):\n",
    "    A[4,i] = A[3,i]-1\n",
    "print \"The sixth row denotes the square of elements of fourth row \"\n",
    "for i in range(0,11):\n",
    "    A[5,i] = A[3,i]**2\n",
    "print A\n",
    "a = 0\n",
    "print \"The sum of elements of fourth row=\"\n",
    "for i in range(0,11):\n",
    "    a = a+A[3,i]\n",
    "print a\n",
    "b = 0\n",
    "print \"The sum of elements of sixth row= \"\n",
    "for i in range(0,11):\n",
    "    b = b + A[5,i]\n",
    "print b\n",
    "print \"Standard deviation\"\n",
    "d = (b/(n-1))**0.5\n",
    "t = (1-0)*(n)**0.5/2.24\n",
    "print \"d = \",d\n",
    "print \"t = \",t"
   ]
  }
 ],
 "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
}