summaryrefslogtreecommitdiff
path: root/Higher_Engineering_Mathematics_by_B._S._Grewal/chapter23_1.ipynb
blob: a7ba913c8311e985dfe75fc652953623b7d86a0b (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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 23 : Statistical Methods"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.1, page no. 618"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row of A denotes the no. of students falling in the marks group starting from (5 −10)... till (40−45)\n",
      "the second row denotes cumulative frequency (less than)\n",
      "the third row denotes cumulative frequency(more than)\n",
      "[[  5.   6.  15.  10.   5.   4.   2.   2.]\n",
      " [  5.  11.  26.  36.  41.  45.  47.  49.]\n",
      " [ 49.  44.  38.  23.  13.   8.   4.   2.]]\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([3,8])\n",
    "print \"The first row of A denotes the no. of students falling in the marks group starting from (5 −10)... till (40−45)\"\n",
    "A[0] = [5,6,15,10,5,4,2,2]\n",
    "print \"the second row denotes cumulative frequency (less than)\"\n",
    "A[1,0] = 5\n",
    "for i in range(1,8):\n",
    "    A[1,i] = A[1,i-1]+A[0,i]\n",
    "print \"the third row denotes cumulative frequency(more than)\"\n",
    "A[2,0] = 49\n",
    "for i in range (1,8):\n",
    "    A[2,i] = A[2,i-1]-A[0,i-1]\n",
    "print A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.2, page no. 619"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row of A represents the mid values of weekly earnings having interval of 2 in each class=x \n",
      "The second row denotes the no. of employees or in other words frequency=f \n",
      "Third row denotes f∗x\n",
      "Fourth row denotes u=(x−25)/2 \n",
      "Fifth row denotes f∗x\n",
      "[[  1.10000000e+01   1.30000000e+01   1.50000000e+01   1.70000000e+01\n",
      "    1.90000000e+01   2.10000000e+01   2.30000000e+01   2.50000000e+01\n",
      "    2.70000000e+01   2.90000000e+01   3.10000000e+01   3.30000000e+01\n",
      "    3.50000000e+01   3.70000000e+01   3.90000000e+01   4.10000000e+01]\n",
      " [  3.00000000e+00   6.00000000e+00   1.00000000e+01   1.50000000e+01\n",
      "    2.40000000e+01   4.20000000e+01   7.50000000e+01   9.00000000e+01\n",
      "    7.90000000e+01   5.50000000e+01   3.60000000e+01   2.60000000e+01\n",
      "    1.90000000e+01   1.30000000e+01   9.00000000e+00   7.00000000e+00]\n",
      " [  3.30000000e+01   7.80000000e+01   1.50000000e+02   2.55000000e+02\n",
      "    4.56000000e+02   8.82000000e+02   1.72500000e+03   2.25000000e+03\n",
      "    2.13300000e+03   1.59500000e+03   1.11600000e+03   8.58000000e+02\n",
      "    6.65000000e+02   4.81000000e+02   3.51000000e+02   2.87000000e+02]\n",
      " [ -7.00000000e+00  -6.00000000e+00  -5.00000000e+00  -4.00000000e+00\n",
      "   -3.00000000e+00  -2.00000000e+00  -1.00000000e+00   0.00000000e+00\n",
      "    1.00000000e+00   2.00000000e+00   3.00000000e+00   4.00000000e+00\n",
      "    5.00000000e+00   6.00000000e+00   7.00000000e+00   8.00000000e+00]\n",
      " [ -2.10000000e+01  -3.60000000e+01  -5.00000000e+01  -6.00000000e+01\n",
      "   -7.20000000e+01  -8.40000000e+01  -7.50000000e+01   0.00000000e+00\n",
      "    7.90000000e+01   1.10000000e+02   1.08000000e+02   1.04000000e+02\n",
      "    9.50000000e+01   7.80000000e+01   6.30000000e+01   5.60000000e+01]]\n",
      "Sum of all elements of third row= 13315.0\n",
      "Sum of all elements of second row= 509.0\n",
      "mean= 26.1591355599\n",
      "Sum of all elements of fifth row=  295.0\n",
      "mean by step deviation method=  26.1591355599\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([5,16])\n",
    "print \"The first row of A represents the mid values of weekly earnings having interval of 2 in each class=x \"\n",
    "A[0] = [11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41]\n",
    "print \"The second row denotes the no. of employees or in other words frequency=f \"\n",
    "A[1]=[3,6,10,15,24,42,75,90,79,55,36,26,19,13,9,7]\n",
    "print \"Third row denotes f∗x\"\n",
    "for i in range(0,16):\n",
    "    A[2,i] = A[0,i]*A[1,i]\n",
    "print \"Fourth row denotes u=(x−25)/2 \"\n",
    "for i in range(0,16):\n",
    "    A[3,i] = (A[0,i]-25)/2\n",
    "print \"Fifth row denotes f∗x\"\n",
    "for i in range(0,16):\n",
    "    A[4,i] = A[3,i]*A[1,i]\n",
    "print A\n",
    "b = 0\n",
    "print \"Sum of all elements of third row=\",\n",
    "for i in range(0,16):\n",
    "    b = b+A[2,i]\n",
    "print b\n",
    "f = 0\n",
    "print \"Sum of all elements of second row=\",\n",
    "for i in range(0,16):\n",
    "    f = f+A[1,i]\n",
    "print f\n",
    "print \"mean=\",b/f\n",
    "d = 0\n",
    "print \"Sum of all elements of fifth row= \",\n",
    "for i in range(0,16):\n",
    "    d = d+A[4,i]\n",
    "print d\n",
    "print \"mean by step deviation method= \",25+(2*d/f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.3, page no. 620"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row of A denotes the no. of students falling in the marks group startin from (5−10)... till (40−45)\n",
      "The second row denotes cumulative frequency (less than)\n",
      "The third row denotes cumulative frequency (more than)\n",
      "[[  5.   6.  15.  10.   5.   4.   2.   2.]\n",
      " [  5.  11.  26.  36.  41.  45.  47.  49.]\n",
      " [ 49.  44.  38.  23.  13.   8.   4.   2.]]\n",
      "Median falls in the class (15−20)=l+((n/2−c)∗h)/f=  19\n",
      "Lower quartile also falls in the class (15−20)=\n",
      "Upper quartile also falls in the class (25−30)=\n",
      "Semiinter quartile range=  5\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([3,8])\n",
    "print \"The first row of A denotes the no. of students falling in the marks group startin from (5−10)... till (40−45)\"\n",
    "\n",
    "A[0] = [5,6,15,10,5,4,2,2]\n",
    "print \"The second row denotes cumulative frequency (less than)\"\n",
    "A[1]=[5,11,26,36,41,45,47,49]\n",
    "print \"The third row denotes cumulative frequency (more than)\"\n",
    "A[2] = [49,44,38,23,13,8,4,2]\n",
    "print A\n",
    "print \"Median falls in the class (15−20)=l+((n/2−c)∗h)/f= \",15+((49/2-11)*5)/15\n",
    "print \"Lower quartile also falls in the class (15−20)=\"\n",
    "Q1 = 15+((49/4-11)*5)/15\n",
    "print \"Upper quartile also falls in the class (25−30)=\"\n",
    "Q3 =25+((3*49/4-36)*5)/5\n",
    "print \"Semiinter quartile range= \",(Q3-Q1)/2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.4, page no. 620"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row of A denotes the roll no. of students form 1 to 10 and that of B denotes form 11 to 20 \n",
      "The second row of A and B denotes the corresponding marks in physics\n",
      "The third row denotes the corresponding marks in chemistry\n",
      "Median marks in physics=arithmetic mean of 10th and 11th student =  26\n",
      "Median marks in chemistry=arithmetic mean of 10th and 11th student =  41\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([3,10])\n",
    "print \"The first row of A denotes the roll no. of students form 1 to 10 and that of B denotes form 11 to 20 \"\n",
    "A[0] = [1,2,3,4,5,6,7,8,9,10]\n",
    "B[0] = [11,12,13,14,15,16,17,18,19,20]\n",
    "print \"The second row of A and B denotes the corresponding marks in physics\"\n",
    "A[1] = [53,54,52,32,30,60,47,46,35,28]\n",
    "B[1] = [25,42,33,48,72,51,45,33,65,29]\n",
    "print \"The third row denotes the corresponding marks in chemistry\"\n",
    "A[2] = [58,55,25,32,26,85,44,80,33,72]\n",
    "B[2] = [10,42,15,46,50,64,39,38,30,36]\n",
    "print \"Median marks in physics=arithmetic mean of 10th and 11th student = \",(28+25)/2\n",
    "print \"Median marks in chemistry=arithmetic mean of 10th and 11th student = \",(72+10)/2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.5, page no. 621"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Let the misssing frequencies be f1 and f2 \n",
      "Sum of given frequencies=12+30+65+25+18 =  150\n",
      "So, f1+f2=229−c =  79\n",
      "Median=46=40+(114.5−(12+30+f1))∗10/65)\n",
      "f1=33.5=34 \n"
     ]
    }
   ],
   "source": [
    "print \"Let the misssing frequencies be f1 and f2 \"\n",
    "print \"Sum of given frequencies=12+30+65+25+18 = \",\n",
    "c =12+30+65+25+18\n",
    "print c\n",
    "print \"So, f1+f2=229−c = \",229-c\n",
    "print \"Median=46=40+(114.5−(12+30+f1))∗10/65)\"\n",
    "print \"f1=33.5=34 \"\n",
    "f1 = 34\n",
    "f2 = 45"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.6, page no. 622"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Let the eqidistance be s, then\n",
      "Average speed = total distance/total time taken 1800/47\n"
     ]
    }
   ],
   "source": [
    "import sympy\n",
    "\n",
    "s = sympy.Symbol('s')\n",
    "print \"Let the eqidistance be s, then\"\n",
    "t1 = s/30\n",
    "t2 = s/40\n",
    "t3 = s/50\n",
    "print \"Average speed = total distance/total time taken\",3*s/(t1+t2+t3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.7, page no. 623"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row denotes the size of item \n",
      "The second row denotes the corresponding frequency(f)\n",
      "The third row denotes the corresponding deviation(d)\n",
      "The fourth row denotes the corresponding f∗d \n",
      "The fifth row denotes the corresponding f∗dˆ2 \n",
      "[[  6.   7.   8.   9.  10.  11.  12.]\n",
      " [  3.   6.   9.  13.   8.   5.   4.]\n",
      " [ -3.  -2.  -1.   0.   1.   2.   3.]\n",
      " [ -9. -12.  -9.   0.   8.  10.  12.]\n",
      " [ 27.  24.   9.   0.   8.  20.  36.]]\n",
      "Sum of fourth row elements=  0.0\n",
      "Sum of fifth row elements=  124.0\n",
      "Sum of all frequencies =  48.0\n",
      "mean=9+b/d =  9.0\n",
      "Standard deviation = (c/d)ˆ0.5 =  1.60727512683\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([5,7])\n",
    "print \"The first row denotes the size of item \"\n",
    "A[0,:] = [6,7,8,9,10,11,12]\n",
    "print \"The second row denotes the corresponding frequency(f)\"\n",
    "A[1,:] = [3,6,9,13,8,5,4]\n",
    "print \"The third row denotes the corresponding deviation(d)\"\n",
    "A[2,:] = [-3,-2,-1,0,1,2,3]\n",
    "print \"The fourth row denotes the corresponding f∗d \"\n",
    "for i in range(0,7):\n",
    "    A[3,i] = A[1,i]*A[2,i] \n",
    "print \"The fifth row denotes the corresponding f∗dˆ2 \"\n",
    "for i in range(0,7):\n",
    "    A[4,i] = A[1,i]*(A[2,i]**2)\n",
    "print A\n",
    "b = 0\n",
    "print \"Sum of fourth row elements= \",\n",
    "for i in range(0,7):\n",
    "    b = b+A[3,i]\n",
    "print b\n",
    "c = 0\n",
    "print \"Sum of fifth row elements= \",\n",
    "for i in range(0,7):\n",
    "    c = c+A[4,i]\n",
    "print c\n",
    "d = 0\n",
    "print \"Sum of all frequencies = \",\n",
    "for i in range(0,7):\n",
    "    d = d+A[1,i]\n",
    "print d\n",
    "print \"mean=9+b/d = \",9+b/d\n",
    "print \"Standard deviation = (c/d)ˆ0.5 = \",(c/d)**0.5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.8, page no. 624"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row of A represents the mid values of wage classes having interval of 8 in each class=x \n",
      "The second row denotes the no. of men or in other words frequency=f \n",
      "Third row denotes f∗x \n",
      "Fourth row denotes d=(x−32.5)/8 \n",
      "Fifth row denotes f∗d \n",
      "Sixth row denotes f∗(dˆ2)\n",
      "[[   8.5   16.5   24.5   32.5   40.5   48.5   56.5   64.5   72.5]\n",
      " [   2.    24.    21.    18.     5.     3.     5.     8.     2. ]\n",
      " [  17.   396.   514.5  585.   202.5  145.5  282.5  516.   145. ]\n",
      " [  -3.    -2.    -1.     0.     1.     2.     3.     4.     5. ]\n",
      " [  -6.   -48.   -21.     0.     5.     6.    15.    32.    10. ]\n",
      " [  18.    96.    21.     0.     5.    12.    45.   128.    50. ]]\n",
      "Sum of all elements of sixth row=  375.0\n",
      "Sum of all elements of second row=  88.0\n",
      "mean=  4.26136363636\n",
      "Sum of all elements of fifth row=  Mean wage=  31.8636363636\n",
      "standard deviation=  34.0402892562\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([6,9])\n",
    "print \"The first row of A represents the mid values of wage classes having interval of 8 in each class=x \"\n",
    "A[0] = [8.5,16.5,24.5,32.5,40.5,48.5,56.5,64.5,72.5]\n",
    "print \"The second row denotes the no. of men or in other words frequency=f \"\n",
    "A[1] = [2,24,21,18,5,3,5,8,2]\n",
    "print \"Third row denotes f∗x \"\n",
    "for i in range(0,9):\n",
    "    A[2,i] = A[0,i]*A[1,i] \n",
    "print \"Fourth row denotes d=(x−32.5)/8 \"\n",
    "for i in range(0,9):\n",
    "    A[3,i] = (A[0,i]-32.5)/8\n",
    "print \"Fifth row denotes f∗d \"\n",
    "for i in range(0,9):\n",
    "    A[4,i] = A[3,i]*A[1,i]\n",
    "print \"Sixth row denotes f∗(dˆ2)\"\n",
    "for i in range(0,9):\n",
    "    A[5,i] = A[3,i]**2*A[1,i]\n",
    "print A\n",
    "b = 0\n",
    "print \"Sum of all elements of sixth row= \",\n",
    "for i in range(0,9):\n",
    "    b = b+A[5,i]\n",
    "print b\n",
    "f = 0\n",
    "print \"Sum of all elements of second row= \",\n",
    "for i in range(0,9):\n",
    "    f = f+A[1,i]\n",
    "print f\n",
    "print \"mean= \",b/f\n",
    "d = 0\n",
    "print \"Sum of all elements of fifth row= \",\n",
    "for i in range(0,9):\n",
    "    d = d+A[4,i]\n",
    "print \"Mean wage= \",32.5+(8*d/f)\n",
    "print \"standard deviation= \",8*(b/f-(d/f)**2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.9, page no. 626"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row of A denotes the scores of A and that of B denotes that of B \n",
      "The second row of A and B denotes the corresponding deviation \n",
      "The third row of A and B denotes the corresponding deviation square \n",
      "[[   12.   115.     6.    73.     7.    19.   119.    36.    84.    29.]\n",
      " [  -39.    64.   -45.    22.   -44.   -32.    68.   -15.    33.   -22.]\n",
      " [ 1521.  4096.  2025.   484.  1936.  1024.  4624.   225.  1089.   484.]]\n",
      "[[   47.    12.    16.    42.     4.    51.    37.    48.    13.     0.]\n",
      " [   -4.   -39.   -35.    -9.   -47.     0.   -14.    -3.   -38.   -51.]\n",
      " [   16.  1521.  1225.    81.  2209.     0.   196.     9.  1444.  2601.]]\n",
      "Sum of second row elements of  A=b= -10.0\n",
      "sum of second row elements of B=c= -240.0\n",
      "Sum of third row elements of A=d= 17508.0\n",
      "Sum of second row elements of B=e= 9302.0\n",
      "Arithmetic mean of A=  50.0\n",
      "Standard deviation of A=  41.8306108012\n",
      "Arithmetic mean of B=  27.0\n",
      "Standard deviation of A=  18.8202019118\n",
      "Coefficient of variation of A= 83.6612216024\n",
      "Coefficient of variation of B= 69.7044515251\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([3,10])\n",
    "B = numpy.zeros([3,10])\n",
    "print \"The first row of A denotes the scores of A and that of B denotes that of B \"\n",
    "A[0] = [12,115,6,73,7,19,119,36,84,29]\n",
    "B[0] = [47,12,16,42,4,51,37,48,13,0]\n",
    "print \"The second row of A and B denotes the corresponding deviation \"\n",
    "for i in range (0,10):\n",
    "    A[1,i] = A[0,i]-51\n",
    "    B[1,i] = B[0,i]-51\n",
    "print \"The third row of A and B denotes the corresponding deviation square \"\n",
    "for i in range (0,10):\n",
    "    A[2,i] = A[1,i]**2\n",
    "    B[2,i] = B[1,i]**2\n",
    "print A\n",
    "print B\n",
    "b = 0\n",
    "print \"Sum of second row elements of  A=b=\",\n",
    "for i in range (0,10):\n",
    "    b = b+A[1,i]\n",
    "print b\n",
    "c = 0\n",
    "print \"sum of second row elements of B=c=\",\n",
    "for i in range (0,10):\n",
    "    c = c+B[1,i]\n",
    "print c\n",
    "d = 0\n",
    "print \"Sum of third row elements of A=d=\",\n",
    "for i in range (0,10):\n",
    "    d = d+A[2,i]\n",
    "print d\n",
    "e = 0\n",
    "print \"Sum of second row elements of B=e=\",\n",
    "for i in range (0,10):\n",
    "    e = e+B[2,i]\n",
    "print e\n",
    "print \"Arithmetic mean of A= \",\n",
    "f = 51+b/10\n",
    "print f\n",
    "print \"Standard deviation of A= \",\n",
    "g = (d/10-(b/10)**2)**0.5\n",
    "print g\n",
    "print \"Arithmetic mean of B= \",\n",
    "h = 51+c/10\n",
    "print h\n",
    "print \"Standard deviation of A= \",\n",
    "i = (e/10-(c/10)**2)**0.5\n",
    "print i\n",
    "print \"Coefficient of variation of A=\",(g/f)*100\n",
    "print \"Coefficient of variation of B=\",(i/h)*100"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.10, page no. 628"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "If m is the mean of entire data, then\n",
      "116\n",
      "If s is the standard deviation of entire data, then \n",
      "7.74596669241\n"
     ]
    }
   ],
   "source": [
    "print \"If m is the mean of entire data, then\"\n",
    "m = (50*113+60*120+90*115)/(50+60+90)\n",
    "print m\n",
    "print \"If s is the standard deviation of entire data, then \"\n",
    "s = (((50*6**2)+(60*7**2)+(90*8**2)+(50*3**2)+(60*4**2)+(90*1**2))/200)**0.5\n",
    "print s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.12, page no. 629"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row of A denotes the no. of persons falling in the weight group starting from (70−80)... till (140−150)\n",
      "The second row denotes cumulative frequency\n",
      "Median falls in the class (110−120) = l+((n/2−c)∗h)/f=  111\n",
      "Lower quartile also falls in the class (90−100)=  97.8571428571\n",
      "Upper quartile also falls in the class (120−130)=  123.444444444\n",
      "Quartile coefficient of skewness=  -0.0272952853598\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([2,8])\n",
    "print \"The first row of A denotes the no. of persons falling in the weight group starting from (70−80)... till (140−150)\"\n",
    "A[0] = [12,18,35,42,50,45,20,8]\n",
    "print \"The second row denotes cumulative frequency\"\n",
    "A[1,0] = 12\n",
    "for i in range(1,8):\n",
    "    A[1,i] = A[1,i-1]+A[0,i]\n",
    "print \"Median falls in the class (110−120) = l+((n/2−c)∗h)/f= \",\n",
    "Q2 = 110+(8*10)/50\n",
    "print Q2\n",
    "print \"Lower quartile also falls in the class (90−100)= \",\n",
    "Q1 = 90+(57.5-30)*10/35\n",
    "print Q1\n",
    "print \"Upper quartile also falls in the class (120−130)= \",\n",
    "Q3 = 120+(172.5-157)*10/45\n",
    "print Q3\n",
    "print \"Quartile coefficient of skewness= \",(Q1+Q3-2*Q2)/(Q3-Q1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23.13, page no. 631"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first row of A denotes the corresponding I.R. of students \n",
      "The second row denotes the corresponding deviation of I.R.\n",
      "The third row denotes the square of corresponding deviation of I.R.\n",
      "The fourth row denotes the corresponding E.R. of students \n",
      "The fifth row denotes the corresponding deviation of E.R.\n",
      "The sixth row denotes the square of corresponding deviation of E.R.\n",
      "The seventh row denotes the product of the two corresponding deviations\n",
      "[[ 105.  104.  102.  101.  100.   99.   98.   96.   93.   92.]\n",
      " [   6.    5.    3.    2.    1.    0.   -1.   -3.   -6.   -7.]\n",
      " [  36.   25.    9.    4.    1.    0.    1.    9.   36.   49.]\n",
      " [ 101.  103.  100.   98.   95.   96.  104.   92.   97.   94.]\n",
      " [   3.    5.    2.    0.   -3.   -2.    6.   -6.   -1.   -4.]\n",
      " [   9.   25.    4.    0.    9.    4.   36.   36.    1.   16.]\n",
      " [  18.   25.    6.    0.   -3.   -0.   -6.   18.    6.   28.]]\n",
      "The sum of elements of first row=a =  990.0\n",
      "The sum of  elements of second row=b =  0.0\n",
      "The sum of elements of third row=c =  170.0\n",
      "The sum of elements of fourth row=d =  980.0\n",
      "The sum of elements of fifth row=e =  0.0\n",
      "The sum of elements of sixth row=d =  140.0\n",
      "The sum of elements of seventh row=d =  92.0\n",
      "Coefficient of correlation =  0.596347425668\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "\n",
    "A = numpy.zeros([7,10])\n",
    "print \"The first row of A denotes the corresponding I.R. of students \"\n",
    "A[0] = [105,104,102,101,100,99,98,96,93,92]\n",
    "print \"The second row denotes the corresponding deviation of I.R.\"\n",
    "for i in range(0,10):\n",
    "    A[1,i] = A[0,i]-99\n",
    "print \"The third row denotes the square of corresponding deviation of I.R.\"\n",
    "for i in range(0,10):\n",
    "    A[2,i] = A[1,i]**2\n",
    "print \"The fourth row denotes the corresponding E.R. of students \"\n",
    "A[3] = [101,103,100,98,95,96,104,92,97,94]\n",
    "print \"The fifth row denotes the corresponding deviation of E.R.\"\n",
    "for i in range(0,10):\n",
    "    A[4,i] = A[3,i]-98\n",
    "print \"The sixth row denotes the square of corresponding deviation of E.R.\"\n",
    "for i in range(0,10):\n",
    "    A[5,i] = A[4,i]**2\n",
    "print \"The seventh row denotes the product of the two corresponding deviations\"\n",
    "for i in range(0,10):\n",
    "    A[6,i] = A[1,i]*A[4,i]\n",
    "print A\n",
    "a = 0\n",
    "print \"The sum of elements of first row=a = \",\n",
    "for i in range(0,10):\n",
    "    a = a+A[0,i]\n",
    "print a\n",
    "b = 0 \n",
    "print \"The sum of  elements of second row=b = \",\n",
    "for i in range(0,10):\n",
    "    b = b+A[1,i]\n",
    "print b\n",
    "c = 0\n",
    "print \"The sum of elements of third row=c = \",\n",
    "for i in range(0,10):\n",
    "    c = c+A[2,i]\n",
    "print c\n",
    "d = 0\n",
    "print \"The sum of elements of fourth row=d = \",\n",
    "for i in range(0,10):\n",
    "    d = d+A[3,i]\n",
    "print d\n",
    "e = 0\n",
    "print \"The sum of elements of fifth row=e = \",\n",
    "for i in range(0,10):\n",
    "    e = e+A[4,i]\n",
    "print e\n",
    "f = 0\n",
    "print \"The sum of elements of sixth row=d = \",\n",
    "for i in range(0,10):\n",
    "    f = f+A[5,i]\n",
    "print f\n",
    "g = 0\n",
    "print \"The sum of elements of seventh row=d = \",\n",
    "for i in range(0,10):\n",
    "    g = g+A[6,i]\n",
    "print g\n",
    "print \"Coefficient of correlation = \",g/(c*f)**0.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.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}