summaryrefslogtreecommitdiff
path: root/sample_notebooks/ShantanuBhosale/chapter40_1.ipynb
blob: e434627c6b62a5aecd204b88de1586fb1953617a (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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER 40: D.C TRANSMISSION AND DISTRIBUTION\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.1 ,Page No :- 1574"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percentage saving in copper is = 50.0 %.\n"
     ]
    }
   ],
   "source": [
    "#A DC 2-wire feeder supplies a constant load with a sending-end voltage of 220V.Calculate the saving in copper\n",
    "#if this voltage is doubled with power transmitted remaining the same.\n",
    "##################################################################################################################\n",
    "\n",
    "\n",
    "\n",
    "#Given\n",
    "V1 = 220.0\n",
    "V2 = 440.0\n",
    "##Let us assume the wire has##\n",
    "#length -> length \n",
    "#area   -> area\n",
    "#current density -> cd\n",
    "#power  -> P\n",
    "P = 10000.0   #assumption\n",
    "length = 1000.0    #assumption \n",
    "cd = 5.0    #assumption\n",
    "#The values are assumed as these terms cancel out while calculating percentage.\n",
    "I1 = P/V1\n",
    "area  = I1/cd\n",
    "#Vol of Cu required for 220V ->vol1\n",
    "vol1 = 2*area*length\n",
    "\n",
    "\n",
    "I2 = P/V2\n",
    "area  = I2/cd\n",
    "#Vol of Cu required for 440V ->vol2\n",
    "vol2 = 2*area*length\n",
    "\n",
    "#percentage saving of copper is\n",
    "per_cent = ((vol1-vol2)/vol1)*100\n",
    "print 'percentage saving in copper is ',per_cent,'%.'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.2 ,Page No :- 1577"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum voltage drop from one end is =  12.0 V.\n",
      "Maximum voltage drop from both end is =  3.0 V.\n"
     ]
    }
   ],
   "source": [
    "#A uniform 2-wire d.c distributor 200 metres long is loaded with 2 amperes/metre.Resistance of\n",
    "#single wire is 0.3 ohm/kilometre.Calculate the maximum voltage drop if the distributor is fed\n",
    "#(a)from one end (b)from both ends with equal voltages.\n",
    "#################################################################################################\n",
    "\n",
    "#Given\n",
    "length = 200.0        #metres\n",
    "#current per unit length is\n",
    "cur = 2.0             #amp/metre\n",
    "#resistance per unit length is\n",
    "res = 0.3/1000        #ohm/metre\n",
    "\n",
    "#total resistance is\n",
    "R = res*length        #ohm\n",
    "#total current is\n",
    "I = cur*length        #amp\n",
    "#Total drop over a distributor fed from one end is given by\n",
    "drop1 = (1/2.0)*I*R        #volts\n",
    "#Total drop over a distributor fed from both ends is given by\n",
    "drop2 = (1/8.0)*I*R\n",
    "print 'Maximum voltage drop from one end is = ',drop1,'V.'\n",
    "print 'Maximum voltage drop from both end is = ',drop2,'V.'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.3 ,Page No :- 1577"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cross sectional area of distributor = 116.412 cm^2\n"
     ]
    }
   ],
   "source": [
    "#A 2-wire d.c distributor AB is 300 metres long.It is fed at point A.The various loads and\n",
    "#their positions are given below.\n",
    "#      At point       distance from A in metres     concentrated load in A\n",
    "#         C                     40                             30\n",
    "#         D                     100                            40                \n",
    "#         E                     150                            100\n",
    "#         F                     250                            50\n",
    "#If the maximum permissible voltage drop is not to exceed 10V,find the cross-sectional\n",
    "#area of the distributor.Take resistivity = 1.78*10^(-8) ohm-m.\n",
    "###########################################################################################\n",
    "\n",
    "\n",
    "#Given\n",
    "resistivity = 1.78e-8     #ohm-m\n",
    "drop_max    = 10.0          #V\n",
    "#loads and their positions\n",
    "I1 = 30.0    #A\n",
    "l1 = 40.0    #m\n",
    "I2 = 40.0    #A\n",
    "l2 = 100.0   #m\n",
    "I3 = 100.0   #A\n",
    "l3 = 150.0   #m\n",
    "I4 = 50   #A\n",
    "l4 = 250   #m\n",
    "#We know that R = resistivity*length/Area\n",
    "#Also max drop = I1*R1 + I2*R2 + I3*R3 + I4*R4 , using this\n",
    "area = 2*(I1*l1 + I2*l2 + I3*l3 + I4*l4)*resistivity/drop_max   #m^2\n",
    "area = area*1000000    #cm^2                 \n",
    "print 'Cross sectional area of distributor =',area,'cm^2'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.4 ,Page No :- 1578"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hence drop at minimum potential where load is 70 A is = 48.4 V.\n"
     ]
    }
   ],
   "source": [
    "#A 2-wire d.c distributor F1F2 1000 metres long is loaded as under:\n",
    "#Distance from F1(in metres): 100    250    500    600    700    800    850    920\n",
    "#Load in amperes:              20     80     50     70     40     30     10     15\n",
    "#The feeding points F1 and F2 are maintained at the same potential.Find which point will have the\n",
    "#minimum potential and what will be the drop at this point?Take the cross-section of the conductors\n",
    "#as 0.35 cm^2 and specific resistance of copper as 1.764*10^(-6) ohm-cm\n",
    "#####################################################################################################\n",
    "\n",
    "#Given\n",
    "import numpy as np\n",
    "resistivity = 1.764e-8           #ohm-m\n",
    "area = 0.35e-4                      #m^2 \n",
    "#loads and their positions taking from F1\n",
    "I1 = 20         #A\n",
    "l1 = 100        #m\n",
    "I2 = 80         #A\n",
    "l2 = 150        #m\n",
    "I3 = 50         #A\n",
    "l3 = 250        #m\n",
    "I4 = 70        #A\n",
    "l4 = 100        #m\n",
    "I5 = 40         #A\n",
    "l5 = 100        #m\n",
    "I6 = 30         #A\n",
    "l6 = 50        #m\n",
    "I7 = 10         #A\n",
    "l7 = 70        #m\n",
    "I8 = 15         #A\n",
    "l8 = 80       #m \n",
    "\n",
    "#sum of loads from F1\n",
    "load1 = I1*l1 + I2*(l1+l2) + I3*(l1+l2+l3)                          #A-m\n",
    "load2 = I8*l8 + I7*(l7+l8) + I6*(l6+l7+l8) + I5*(l5+l6+l7+l8)       #A-m\n",
    "\n",
    "#guessing the point of minimum potential\n",
    "if load1>load2:\n",
    "    load2_new = load2 + I4*(l4+l5+l6+l7+l8)\n",
    "    if load2_new>load1:\n",
    "        pivot = I4\n",
    "\n",
    "#solving 2 equations simultaneously\n",
    "# x + y = 70(pivot) & 47000(load1) + 600(l1+l2+l3)x = 20,700(load2) + 400(l5+l6+l7+l8)y)\n",
    "line1 = l1+l2+l3+l4                   #m\n",
    "line2 = l4+l5+l6+l7+l8                #m \n",
    "\n",
    "a = [[1,1],[line1,-line2]]\n",
    "b = [pivot,load2-load1]\n",
    "soln = np.linalg.solve(a,b)            #soln is array with its elements[x,y]\n",
    "#drop at minimum potential per conductor (in A-m)\n",
    "drop_m = load1 + soln[0]*line1   #A-m\n",
    "\n",
    "#resistance per metre = resistivity/Area\n",
    "res = resistivity/area     #ohm/m\n",
    "\n",
    "#Hence, drop in voltage per conductor is\n",
    "drop = drop_m*res          #V  \n",
    "#drop due to both is\n",
    "drop = drop*2              #V\n",
    "\n",
    "print 'Hence drop at minimum potential where load is',pivot,'A is =',round(drop,2),'V.'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.5 ,Page No :- 1579"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The current entering at A is =  88.6 A \n",
      "The current entering at B is =  211.4 A.\n"
     ]
    }
   ],
   "source": [
    "#The resistance of a cable is 0.1ohm per 1000 metre for both conductors.It is loaded as shown in Fig.40.14(a).\n",
    "#Find the current supplied at A and at B.If both the ends are supplied at 200 V\n",
    "##############################################################################################################\n",
    "\n",
    "#Given\n",
    "#resistance per metre\n",
    "res = 0.1/1000         #ohm/m\n",
    "#loads and their positions taking from A\n",
    "I1 = 50.0      #A\n",
    "l1 = 500.0     #m\n",
    "I2 = 100.0     #A\n",
    "l2 = 700.0     #m\n",
    "I3 = 150.0     #A\n",
    "l3 = 300.0    #m\n",
    "l4 = 250.0     #m    \n",
    "\n",
    "#Assuming I flows from A to B\n",
    "# equation is  res*[500*i + 700(i-50) + 300(i-150) + 250(i-300)] = 0\n",
    "current_i = (I1*l2+(I1+I2)*l3 + (I1+I2+I3)*l4)/(l1+l2+l3+l4)\n",
    "current_AC = current_i\n",
    "current_CD = current_i-I1\n",
    "current_DE = current_CD-I2\n",
    "current_EB = current_DE-I3\n",
    "if current_EB<0:\n",
    "    current_EB = -current_EB;\n",
    "print 'The current entering at A is = ',round(current_i,1),'A '\n",
    "print 'The current entering at B is = ',round(current_EB,1),'A.'    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.6 ,Page No :- 1580"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current supplied at A is =  88.6 A.\n",
      "Current supplied at B is =  -211.4 A.\n",
      "Current in AC is =  88.6 A.\n",
      "Current in CD is =  38.6 A.\n",
      "Current in DE is =  -61.4 A.\n",
      "Current in EB is =  -211.4 A.\n",
      "Drop over AC is =  4.4 V.\n",
      "Drop over CD is =  2.7 V.\n",
      "Drop over DE is =  -1.8 V.\n",
      "Voltage at C is =  195.6 V.\n",
      "Voltage at D is = 192.9 V.\n",
      "Voltage at E is =  194.7 V.\n"
     ]
    }
   ],
   "source": [
    "#The resistance of two conductors of a 2-conductor distributor shown in Fig.39.15 is 0.1ohm per 1000m\n",
    "#for both conductors.Find (a)the current supplied at A(b)the current supplied at B\n",
    "#(c)the current in each section (d)the voltages at C,D and E.Both A and B are maintained at 200V.\n",
    "######################################################################################################\n",
    "\n",
    "#Given\n",
    "#resistance per metre\n",
    "res = 0.1/1000         #ohm/m\n",
    "#loads and their positions taking from A\n",
    "I1 = 50.0      #A\n",
    "l1 = 500.0     #m\n",
    "I2 = 100.0     #A\n",
    "l2 = 700.0     #m\n",
    "I3 = 150.0     #A\n",
    "l3 = 300.0    #m\n",
    "l4 = 250.0     #m    \n",
    "\n",
    "#Assuming I flows from A to B\n",
    "# equation is  res*[500*i + 700(i-50) + 300(i-150) + 250(i-300)] = 0\n",
    "current_i = (I1*l2+(I1+I2)*l3 + (I1+I2+I3)*l4)/(l1+l2+l3+l4)\n",
    "current_AC = current_i\n",
    "current_CD = current_i-I1\n",
    "current_DE = current_CD-I2\n",
    "current_EB = current_DE-I3\n",
    "print \"Current supplied at A is = \",round(current_i,1),\"A.\"\n",
    "print \"Current supplied at B is = \",round(current_EB,1),\"A.\"\n",
    "print \"Current in AC is = \",round(current_i,1),\"A.\"\n",
    "print \"Current in CD is = \",round(current_CD,1),\"A.\"\n",
    "print \"Current in DE is = \",round(current_DE,1),\"A.\"\n",
    "print \"Current in EB is = \",round(current_EB,1),\"A.\"\n",
    "#Drop in volts is (resistance/metre)*length*current\n",
    "drop_AC = res*l1*current_AC         #V\n",
    "drop_CD = res*l2*current_CD          #V \n",
    "drop_DE = res*l3*current_DE          #V\n",
    "print \"Drop over AC is = \",round(drop_AC,1),\"V.\"\n",
    "print \"Drop over CD is = \",round(drop_CD,1),\"V.\"\n",
    "print \"Drop over DE is = \",round(drop_DE,1),\"V.\"\n",
    "\n",
    "#Voltages at C,D,E are\n",
    "volt_C = 200-drop_AC        #V\n",
    "volt_D = volt_C-drop_CD     #V\n",
    "volt_E = volt_D-drop_DE     #V\n",
    "print 'Voltage at C is = ',round(volt_C,1),'V.'\n",
    "print 'Voltage at D is =',round(volt_D,1),'V.'\n",
    "print 'Voltage at E is = ',round(volt_E,1),'V.'\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.7 ,Page No :- 1581"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Therefore point of minimum potential is D and minimum potential is =  246.0 V.\n"
     ]
    }
   ],
   "source": [
    "#A 200 m long distributor is fed from both ends A and B at the same voltage of 250V.The\n",
    "#concentrated loads of 50,40,30 and 25 A are coming on the distributor at distances of 50,75,\n",
    "#100 and 150 m respectively from end A.Determine the minimum potential and locate its positions.\n",
    "#Also,determine the current in each section of the distributor.It is given that the resistance\n",
    "#of the distributor is 0.08ohm per 100 metres for go and return.\n",
    "##################################################################################################\n",
    "\n",
    "\n",
    "#Given\n",
    "#resistance per metre\n",
    "res = 0.08/100           #ohm/m\n",
    "V_A = 250.0                #V\n",
    "V_B = 250.0                #V\n",
    "#load currents and their positions\n",
    "I_C  = 50.0   #A\n",
    "I_D  = 40.0   #A\n",
    "I_E  = 30.0   #A\n",
    "I_F  = 25.0   #A\n",
    "l_AC = 50.0        #m\n",
    "l_CD = 75.0 - l_AC   #m\n",
    "l_DE = 100.0 - l_CD - l_AC        #m\n",
    "l_EF = 150.0 - l_DE - l_CD - l_AC #m\n",
    "l_FB = 200.0-150.0\n",
    "#Assuming I flows from A to B\n",
    "# equation is  res*[50*i + 25(i-50) + 25(i-90) + 50(i-120)+50(i-145)] = 0\n",
    "current_i = (l_CD*I_C + l_DE*(I_C+I_D)+l_EF*(I_C+I_D+I_E) + l_FB*(I_C+I_D+I_E+I_F))/200.0\n",
    "current_AC = current_i\n",
    "current_CD = current_i-I_C\n",
    "current_DE = current_CD-I_D\n",
    "current_EF = current_DE-I_E\n",
    "current_FB = current_EF-I_F\n",
    "#As from figure in the book , point D is at minimum potential\n",
    "if (current_CD>0) & (current_DE<0):\n",
    "    point = \"D\"\n",
    "    \n",
    "#drop in volts = resistance/metre*sum(length*current) \n",
    "drop_d = res*(l_AC*current_AC + l_CD*current_CD)\n",
    "min_pot = V_A-drop_d\n",
    "print \"Therefore point of minimum potential is\",point,\"and minimum potential is = \",round(min_pot,1),\"V.\"    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.8 ,Page No :- 1582"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage at point C is =  250.13 V.\n",
      "Voltage at point D is =  247.73 V.\n"
     ]
    }
   ],
   "source": [
    "#Each conductor of a 2-core distributor,500 metres long has a cross-sectional area\n",
    "#of 2 cm^2.The feeding point A is supplied at 255V and the feeding point B at\n",
    "#250V and load currents of 120A and 160A are taken at points C and D which are\n",
    "#150 metres and 350 metres respectively from the feeding point A.Calculate the\n",
    "#voltage at each load.Specific Resistance of copper is 1.7*10^(-6) ohm-cm\n",
    "##################################################################################\n",
    "\n",
    "#Given\n",
    "area = 2e-4             #m^2\n",
    "resistivity = 1.7e-8    #ohm-m\n",
    "#load currents and their positions\n",
    "i_c = 120.0    #A\n",
    "i_d = 160.0    #A\n",
    "l_ac = 150.0   #m\n",
    "l_cd = 200.0   #m\n",
    "l_db = 150.0   #m\n",
    "V_a = 255.0    #V\n",
    "V_b = 250.0    #V\n",
    "#Resistance = resistivity*length/Area\n",
    "#It is a 2 core distributor.Therefore,resistance per metre is\n",
    "res = 2*resistivity/area   #ohm/m\n",
    "#drop over whole distributor is equal to\n",
    "drop = V_a - V_b     #V\n",
    "#Therefore equation of total drop can be written as\n",
    "# resistivity*(150i+200(i-120)+150(i-280))=5\n",
    "current_i = (drop/res + l_cd*i_c + l_db*(i_c+i_d))/(l_ac+l_cd+l_db)   #A\n",
    "current_ac = current_i          #A\n",
    "current_cd = current_ac-i_c     #A\n",
    "current_db = current_cd-i_d     #A\n",
    "\n",
    "#Voltage at C = 255-drop over AC\n",
    "volt_c = V_a-res*l_ac*current_ac    #V\n",
    "#Voltage at D = 250-drop over DB    \n",
    "volt_d = V_b -res*l_db*abs(current_db) #V\n",
    "print \"Voltage at point C is = \",round(volt_c,2),\"V.\"\n",
    "print \"Voltage at point D is = \",round(volt_d,2),\"V.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.9 ,Page No :- 1583"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Volatge at point Q is =  225.25 V.\n",
      "Voltage at point B is =  236.56 V.\n"
     ]
    }
   ],
   "source": [
    "#A 2-wire distributor 500 metres long is fed at P at 250V and loads of 40A,20A,60A,30A are tapped off\n",
    "#off from points A,B,C and D which are at distances of 100 metres,150 metres,300 metres and 400 metres\n",
    "#from P respectively.The distributor is also uniformly loaded at the rate of 0.1A/m.If the resistance of\n",
    "#the distributor per metre(go and return) is 0.0005 ohm,calculate the voltage at(i)pointQ and(ii)point B.\n",
    "###########################################################################################################\n",
    "\n",
    "#Given\n",
    "V_P = 250.0    #V\n",
    "resistance = 0.0005        #ohm/m\n",
    "\n",
    "#loads and their positions\n",
    "i_a = 40.0     #A\n",
    "i_b = 20.0     #A\n",
    "i_c = 60.0     #A\n",
    "i_d = 30.0     #A\n",
    "l_pa = 100.0     #m\n",
    "l_ab = 150.0-100.0      #m\n",
    "l_bc = 300.0-150.0     #m\n",
    "l_cd = 400.0-300.0     #m\n",
    "#uniform dstributed load\n",
    "cur_uni = 0.1      #A/m\n",
    "\n",
    "\n",
    "#considering drop due to concentrated loading\n",
    "drop_pa = (i_a+i_b+i_c+i_d)*l_pa*resistance      #V\n",
    "drop_ab = (i_b+i_c+i_d)*l_ab*resistance          #V \n",
    "drop_bc = (i_c+i_d)*l_bc*resistance              #V\n",
    "drop_cd = i_d*l_cd*resistance                    #V\n",
    "tot_drop = drop_pa + drop_ab + drop_bc + drop_cd      #V\n",
    "\n",
    "#considering drop due to uniform loading(drop = irl^2/2) l = 500m\n",
    "drop_uni = cur_uni*resistance*(500.0*500.0)/2     #V\n",
    "\n",
    "V_Q = V_P - (tot_drop + drop_uni)   #V\n",
    "#for point B\n",
    "#drop due to concentrated loading\n",
    "drop_b = drop_pa + drop_ab        #V\n",
    "#drop due to uniform loading (drop = ir(lx-x^2/2)) l=500m x=150m\n",
    "drop_ub = cur_uni*resistance*(500*(l_pa+l_ab)-(l_pa+l_ab)*(l_pa+l_ab)/2)   #V\n",
    "\n",
    "V_B = V_P - (drop_b + drop_ub)    #V\n",
    "\n",
    "print \"Volatge at point Q is = \",round(V_Q,2),\"V.\"\n",
    "print \"Voltage at point B is = \",round(V_B,2),\"V.\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.10 ,Page No :- 1583"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current in section AC is =  53.75 A.\n",
      "Current in section CD is =  33.75 A.\n",
      "Current in section DE is =  -6.25 A.\n",
      "Current in section EF is =  -31.25 A.\n",
      "Current in section FB is =  -61.25 A.\n",
      "Minimum voltage is at point D and minimum voltage is =  233.18 V.\n"
     ]
    }
   ],
   "source": [
    "#A distributor AB is fed from both ends.At feeding point A,the voltage is maintained at 236V and at B at 237V.\n",
    "#The total length of the distributor is 200 metres and loads are tapped off as under:\n",
    "#(i) 20A at 50 metres from A   (ii) 40A at 75 metres from A. (iii)25A at 100 metres from A (iv)30A at 150 metres from A\n",
    "#The reistance per kilometre of one conductor is 0.4ohm.Calculate the currents in the various sections of the distributor,\n",
    "#the minimum voltage and the point at which it occurs.\n",
    "###########################################################################################################################\n",
    "\n",
    "\n",
    "#Given\n",
    "#resistance per metre\n",
    "res = 2*0.4/1000      #ohm/m\n",
    "V_a = 236.0    #V\n",
    "V_b = 237.0    #V\n",
    "#loads and their positions\n",
    "i_c = 20.0  #A\n",
    "i_d = 40.0  #A\n",
    "i_e = 25.0  #A\n",
    "i_f = 30.0  #A\n",
    "l_ac = 50.0  #m\n",
    "l_cd = 25.0  #m\n",
    "l_de = 25.0  #m\n",
    "l_ef = 50.0  #m\n",
    "l_fb = 50.0  #m\n",
    "#Voltage drop equation  res*(50i + 25(i-20)+25(i-60) + 50(i-85) + 50(i-115)=-1)\n",
    "current_i = ((V_a-V_b)/res + l_cd*(i_c)+l_de*(i_c+i_d)+l_ef*(i_c+i_d+i_e)+l_fb*(i_c+i_d+i_e+i_f))/200.0\n",
    "current_ac = current_i\n",
    "current_cd = current_ac-i_c\n",
    "current_de = current_cd-i_d\n",
    "current_ef = current_de-i_e\n",
    "current_fb= current_ef-i_f\n",
    "if current_cd>0:\n",
    "    if current_de<0:\n",
    "        point = \"D\"\n",
    "#Minimum potential is at D as shown in figure\n",
    "drop = res*(current_ac*l_ac + current_cd*l_cd)\n",
    "V_d = V_a-drop\n",
    "print \"Current in section AC is = \",round(current_ac,2),\"A.\"\n",
    "print \"Current in section CD is = \",round(current_cd,2),\"A.\"\n",
    "print \"Current in section DE is = \",round(current_de,2),\"A.\"\n",
    "print \"Current in section EF is = \",round(current_ef,2),\"A.\"\n",
    "print \"Current in section FB is = \",round(current_fb,2),\"A.\"\n",
    "print \"Minimum voltage is at point\",point,\"and minimum voltage is = \",round(V_d,2),\"V.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.11 ,Page No :- 1584"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current supplied by feeder at point A is 46.29 A and that by point B is 109.71 A.\n",
      "Voltage at point B is =  240.55 V.\n",
      "Voltage at point C is =  239.63 V.\n",
      "Voltage at point D is =  239.42 V.\n",
      "Voltage at point E is =  239.38 V.\n"
     ]
    }
   ],
   "source": [
    "#A distributor cable AB is fed at its ends A and B.Loads of 12,24,72 and 48 A are taken from the cable at\n",
    "#points C,D,E and F.The resistances of sections AC,CD,DE,EF and FB of the cable are 8,6,4,10 and 5 milliohm\n",
    "#respecively(for the go and return conductors together). The potential difference at point A is 240V,the p.d\n",
    "#at the load F is also to be 240V.Calculate the voltages at the feeding point B,the current supplied by each\n",
    "#feeder and the p.d.s at the loads C,D and E.\n",
    "##############################################################################################################\n",
    "\n",
    "#Given\n",
    "V_a = 240.0    #V  \n",
    "V_f = 240.0    #V\n",
    "#loads and their resistances.\n",
    "i_c = 12.0  #A\n",
    "i_d = 24.0  #A\n",
    "i_e = 72.0  #A\n",
    "i_f = 48.0  #A\n",
    "\n",
    "r_ac = 8e-3   #ohm\n",
    "r_cd = 6e-3   #ohm\n",
    "r_de = 4e-3   #ohm\n",
    "r_ef = 10e-3  #ohm\n",
    "r_fb = 5e-3   #ohm\n",
    "\n",
    "#Voltage drop accross AF is zero.Therefore equation 8i +6(i-12) + 4(i-36)+10(i-108)*10^(-3)\n",
    "current_i = (r_cd*i_c + r_de*(i_c+i_d) + r_ef*(i_c+i_d+i_e))/(28.0e-3)   #A\n",
    "#currents in different sections\n",
    "current_ac = current_i        #A\n",
    "current_cd= current_ac-i_c    #A\n",
    "current_de = current_cd-i_d   #A\n",
    "current_ef = current_de-i_e   #A   \n",
    "current_fb = current_ef-i_f   #A\n",
    "#voltage at different points are\n",
    "V_b = V_f - current_fb*r_fb   #V\n",
    "V_c = V_a - current_ac*r_ac   #V\n",
    "V_d = V_c - current_cd*r_cd   #V\n",
    "V_e = V_d - current_de*r_de   #V \n",
    "\n",
    "print \"Current supplied by feeder at point A is\",round(current_ac,2),\"A and that by point B is\",round(abs(current_fb),2),\"A.\"\n",
    "print \"Voltage at point B is = \",round(V_b,2),\"V.\"\n",
    "print \"Voltage at point C is = \",round(V_c,2),\"V.\"\n",
    "print \"Voltage at point D is = \",round(V_d,2),\"V.\"\n",
    "print \"Voltage at point E is = \",round(V_e,2),\"V.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.12 ,Page No :- 1585"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The current supplied at P is =  143.75 A.\n",
      "The current supplied at Q is =  116.25 A.\n",
      "Power dissipated in distributor is = 847.34 W.\n"
     ]
    }
   ],
   "source": [
    "#A two-wire d.c sdistributor PQ,800 metre long is loaded as under:\n",
    "#Distance from P(metres):    100      250      500      600      700\n",
    "#Loads in amperes:            20       80       50       70       40\n",
    "#The feeding point at P is maintained at 248V and that at Q at 245V.The total resistance of\n",
    "#the distributor(lead and return) is 0.1 ohm.Find (a)the current supplied at P and Q and\n",
    "#(b)the power dissipated in the distributor.\n",
    "##################################################################################################\n",
    "\n",
    "#Given\n",
    "V_p  = 248.0     #V\n",
    "V_q  = 245.0     #V\n",
    "res  = 0.1/800    #ohm/m \n",
    "#loads and their positions\n",
    "i1 = 20.0     #A\n",
    "i2 = 80.0     #A\n",
    "i3 = 50.0     #A\n",
    "i4 = 70.0     #A\n",
    "i5 = 40.0     #A\n",
    "l1 = 100.0           #m\n",
    "l2 = 250.0-100.0     #m\n",
    "l3 = 500.0 -250.0    #m\n",
    "l4 = 600.0-500.0     #m\n",
    "l5 = 700.0-600.0     #m\n",
    "l6 = 800.0-700.0     #m\n",
    "#drop accross the distributor :- 1/8000(100i + 150(i-20) + 250(i-100)+ 100(i-150)+100(i-220)+100(i-260) )=3\n",
    "current_i = ((V_p-V_q)/res + l2*i1+l3*(i1+i2)+l4*(i1+i2+i3)+l5*(i1+i2+i3+i4)+l6*(i1+i2+i3+i4+i5))/800.0\n",
    "current_p = current_i       #A\n",
    "current_2 = current_p-i1    #A\n",
    "current_3 = current_2-i2    #A\n",
    "current_4 = current_3-i3    #A\n",
    "current_5 = current_4-i4    #A\n",
    "current_q = current_5-i5    #A\n",
    "#Power loss = sum(I^2R)\n",
    "loss = res*(current_p*current_p*l1 + current_2*current_2*l2 + current_3*current_3*l3 + current_4*current_4*l4 + current_5*current_5*l5 + current_q*current_q*l6)\n",
    "print \"The current supplied at P is = \",round(current_p,2),\"A.\"\n",
    "print \"The current supplied at Q is = \",round(abs(current_q),2),\"A.\"\n",
    "print \"Power dissipated in distributor is =\",round(loss,2),\"W.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.13 ,Page No :- 1586"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The point of minimum potential is D and minimum potential is =  231.76 V.\n",
      "Current fed at the end A is =  366.0 A.\n",
      "Current fed at the end B is =  454.0 A.\n"
     ]
    }
   ],
   "source": [
    "#The two conductors of a d.c distributor cable 1000m long have a total resistance of 0.1 ohm.\n",
    "#The ends A and B are fed at 240V.The cable is uniformly loaded at 0.5 A per metre length\n",
    "#and has concentrated loads of 120A,60A,100A and 40A at points distant 200,400,700 and 900m.\n",
    "#respectively from the end A.Calculate (i)the point of minimum potential on the distributor\n",
    "#(ii)the value of minimum potential and (iii) currents fed at the ends A and B.\n",
    "###############################################################################################\n",
    "\n",
    "#Given\n",
    "V_a = 240.0   #V\n",
    "V_b = 240.0   #V\n",
    "res = 0.1/1000   #ohm/m\n",
    "#concentrated loads and their positions\n",
    "i_c = 120.0       #A\n",
    "i_d = 60.0        #A\n",
    "i_e = 100.0       #A\n",
    "i_f = 40.0        #A\n",
    "l_ac = 200.0      #m\n",
    "l_cd = 400.0-200.0    #m\n",
    "l_de = 700.0-400.0    #m\n",
    "l_ef = 900.0-700.0    #m\n",
    "l_fb = 1000.0-900.0    #m\n",
    "#Uniform loading\n",
    "cur_uni = 0.5     #A/m\n",
    "#Equation for drop from A to B -> (1/10000)*(200i + 200(i-120)+ 300(i-180)+200(i-280)+100(i-320))=0\n",
    "current_i = (l_cd*i_c + l_de*(i_c+i_d)+l_ef*(i_c+i_d+i_e)+l_fb*(i_c+i_d+i_e+i_f))/1000\n",
    "\n",
    "#point of minimum potential\n",
    "current_ac = current_i       #A\n",
    "current_cd = current_ac-i_c    #A\n",
    "current_de = current_cd-i_d    #A\n",
    "current_ef = current_de-i_e    #A\n",
    "current_fb = current_ef-i_f    #A\n",
    "\n",
    "if current_cd>0:\n",
    "    if current_de<0:\n",
    "        point = \"D\"\n",
    "#As from figure it is inferred that point of minimum potential is D.\n",
    "#Therefore,uniform load from point A to D(supplied from A)\n",
    "cur_uni_A = cur_uni*(l_ac + l_cd)    #A\n",
    "cur_A = cur_uni_A + current_ac     #A\n",
    "#Therefore,uniform load from point B to D(supplied from B)\n",
    "cur_uni_B = cur_uni*(l_de + l_ef + l_fb)    #A\n",
    "cur_B = cur_uni_B + abs(current_fb)     #A\n",
    "\n",
    "#drop at D due to concentrated load(from A)\n",
    "drop_con = res*(current_ac*l_ac + current_cd*l_cd)\n",
    "#drop at D due to uniform load(from A)[formula-> irl^2/2]\n",
    "drop_uni = cur_uni*res*(l_ac+l_cd)*(l_ac+l_cd)/2\n",
    "#total drop is\n",
    "drop_tot = drop_con + drop_uni\n",
    "\n",
    "#potential at D is\n",
    "V_d = V_a - drop_tot\n",
    "print \"The point of minimum potential is\",point,\"and minimum potential is = \",round(V_d,2),\"V.\"\n",
    "print \"Current fed at the end A is = \",round(cur_A,2),\"A.\"\n",
    "print \"Current fed at the end B is = \",round(cur_B,2),\"A.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.14 ,Page No :- 1587"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage V is =  8.62 V.\n",
      "Cross-sectional Area A is =  2.78 cm^2.\n",
      "Cross-sectional Area A1 is =  0.26 cm^2.\n",
      "Cross-sectional Area A2 is =  2.24 cm^2.\n"
     ]
    }
   ],
   "source": [
    "#It is proposed to lay out a d.c distribution system comprising three sections-the first section consists\n",
    "#of a cable from the sub-station to a point distant 800 metres from which two cables are taken,one 350 metres\n",
    "#long supplying a load of 22kW and the other 1.5 kilometre long and supplying a load of 44kW.Calculate the\n",
    "#cross-sectional area of each cable so that the total weight of copper required shall be minimum if the maximum\n",
    "#drop of voltage along the cable is not to exceed 5% of the normal voltage of 440V at the consumer's premises.\n",
    "#Take specific resistance of copper at working temperature equal to 2*10e-7 ohm-cm.\n",
    "###################################################################################################################\n",
    "\n",
    "#Given\n",
    "resistivity = 2*10e-7   #ohm-cm\n",
    "dist = 800.0*100          #cm\n",
    "#Current taken from 350m section\n",
    "cur_1 = 22000.0/440\n",
    "#Current taken from 1.5km section\n",
    "cur_2 = 44000.0/440\n",
    "#Therefore,current in first section\n",
    "cur = cur_1 + cur_2\n",
    "#Let us assume\n",
    "#V->voltage drop accross first section\n",
    "#R->resistance of the first section\n",
    "#A->cross-sectional area of te first section\n",
    "\n",
    "from sympy import Eq, var, solve\n",
    "var('V') \n",
    "#Now , R = V/I\n",
    "R = V/cur\n",
    "# A = resistivity*l/R -> A = resistivity*l*I/V \n",
    "A = resistivity*dist/R\n",
    "#Max allowable drop\n",
    "max_drop = (5.0/100)*440.0\n",
    "#Voltage drop along other sections\n",
    "vol_drop = max_drop - V\n",
    "#Cross-sectional area of 350 m   A = resistivity*l/R \n",
    "A1 = resistivity*350.0*100*cur_1/(vol_drop)\n",
    "#Cross-sectional area of 1.5km   A = resistivity*l/R \n",
    "A2 = resistivity*1500.0*100*cur_2/(vol_drop)\n",
    "\n",
    "\n",
    "#Now,Total weight is propotional to total volume \n",
    "W = 800.0*A + 350.0*A1+1500.0*A2\n",
    "Diff = W.diff(V)\n",
    "eq = Eq(Diff,0)\n",
    "\n",
    "V = solve(eq)\n",
    "#We get 2 values of V of which Negative is not possible.Therefore,\n",
    "V = float(V[1])\n",
    "A = resistivity*dist*cur/V\n",
    "vol_drop = max_drop - V\n",
    "A1 = resistivity*350.0*100*cur_1/vol_drop\n",
    "A2 = resistivity*1500.0*100*cur_2/vol_drop\n",
    "print \"Voltage V is = \",round(V,2),\"V.\"\n",
    "print \"Cross-sectional Area A is = \",round(A,2),\"cm^2.\"\n",
    "print \"Cross-sectional Area A1 is = \",round(A1,2),\"cm^2.\"\n",
    "print \"Cross-sectional Area A2 is = \",round(A2,2),\"cm^2.\"\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.15 ,Page No :- 1588"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The point of minimum potential is at 261.74 m from A.\n",
      "The minimum potential is =  247.34 V.\n"
     ]
    }
   ],
   "source": [
    "#A d.c two-wire distributor AB is 450m long and is fed at both ends at 250 volts.It is loaded as follows:20A at 60m from A,\n",
    "#40A at 100m from A and a uniform loading of 1.5A/m from 200 to 450m from A.The resistance of each conductor is\n",
    "#0.05ohm/km.Find the point of minimum potential and its potential.\n",
    "####################################################################################################################\n",
    "\n",
    "#Given\n",
    "V_a = 250.0  #V\n",
    "V_b = 250.0  #V\n",
    "res = 0.05/1000    #ohm/m\n",
    "cur_uni = 1.5      #A/m (uniform loading)\n",
    "#loads and positions\n",
    "i_c = 20.0   #A\n",
    "i_d = 40.0   #A\n",
    "l_ac = 60.0   #m\n",
    "l_cd = 40.0   #m\n",
    "l_de = 100.0  #m\n",
    "l_eb = 250.0  #m\n",
    "\n",
    "#Let us assume that point of minimum potential is D and let i be current in section CD.\n",
    "#Therefore,current from B is (40-i).If r is resistance then\n",
    "#(20+i)*60r + i*40r = (40-i)*350r + 1.5*r*250^2/2   [drop over AD = drop over BD as V_a = V_b]\n",
    "\n",
    "cur_i = (i_d*(l_de+l_eb)*res + cur_uni*res*l_eb*l_eb/2 - i_c*l_ac*res)/((l_ac+l_cd+l_de+l_eb)*res)   #A\n",
    "\n",
    "#cur_i > 40 i.e 40-i is negative,it means D is not point of minimum potential.Let F be point of minimum potential(between DB)\n",
    "#current in section DF is\n",
    "cur_df = cur_i-i_d      #A\n",
    "\n",
    "#distance EF\n",
    "dist_ef = cur_df/cur_uni    #m\n",
    "\n",
    "#distance of F from A is\n",
    "dist = l_ac + l_cd + l_de + dist_ef   #m\n",
    "\n",
    "#total drop over AF is [(20+i)*60r + i*40r+ (i-40)*161.7r - 1.5*r*61.7^2/2\n",
    "drop_af = 2*res*((i_c+cur_i)*l_ac + cur_i*l_cd + cur_df*(l_de+dist_ef)-cur_uni*dist_ef*dist_ef/2)  #V\n",
    "#potential at F\n",
    "V_f = V_a - drop_af      #V\n",
    "print \"The point of minimum potential is at\",round(dist,2),\"m from A.\"\n",
    "print \"The minimum potential is = \",round(V_f,2),\"V.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.16 ,Page No :- 1588"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current fed at A is =  225.0 A.\n",
      "Current fed at B is =  475.0 A.\n",
      "Point of minimum potential from B is =  475.0 metres.\n",
      "Voltage at minimum potential is =  230.72 V.\n"
     ]
    }
   ],
   "source": [
    "#A two-wire d.c distributor AB,1000 metres long,is supplied from both ends,240V at A and 242V at B.There is a\n",
    "#concentrated load of 200A at a distance of 400 metre from A and a uniformly distrubuted load of 1.0A/m between\n",
    "#the mid-point and end B.Determine (i)the currents fed at A and B(ii)the point of minimum potential and\n",
    "#(iii)voltage at this point.Take cable resistance as 0.005 ohm per 100 metre each core.\n",
    "#####################################################################################################################\n",
    "\n",
    "#Given\n",
    "#resistance per 100 metres\n",
    "res = 2*0.005/100         #ohm/m\n",
    "cur_uni = 1.0           #A/m\n",
    "cur_con = 200.0         #A\n",
    "len_uni = 500.0\n",
    "#Let us assume that Ib current flows from point B.\n",
    "#Considering a element dx in BD(500 metres) at a distance of X units(100 m each)\n",
    "#voltage drop over dx = (1-100*x)*res*dx\n",
    "#voltage drop over BD by integrating is = 0.05*Ib - 12.5\n",
    "#voltage drop over DC = (Ib-500)*0.01\n",
    "#voltage drop over CA = (Ib-700)*0.01*4\n",
    "#total drop over AB = \n",
    "tot_drop = 242.0-240.0\n",
    "#summation of drops from AC + CD + DB\n",
    "from sympy import Eq, var, solve\n",
    "var('Ib') \n",
    "sum =  (Ib-500)*0.01 +(Ib-700)*0.01*4 + 0.05*Ib - 12.5\n",
    "\n",
    "eq = Eq(sum,tot_drop)\n",
    "\n",
    "Ib =  solve(eq)\n",
    "Ib = float(Ib[0])\n",
    "#Total current\n",
    "cur_tot = len_uni*cur_uni + cur_con\n",
    "Ia = cur_tot - Ib                 #A\n",
    "#Current in distributed load\n",
    "cur_dis = Ia-cur_con              #A\n",
    "#point of minimum potential from D is\n",
    "distD = cur_dis/cur_uni\n",
    "#Therefore distance from B is\n",
    "distB = len_uni-distD\n",
    "#Therefore voltage drop is\n",
    "from scipy.integrate import quad\n",
    "\n",
    "def integrand(x):\n",
    "    return (Ib-100*x)*res*100\n",
    "\n",
    "ans, err = quad(integrand, 0, (distB/100))\n",
    "#Therefore potential of M is\n",
    "pot_M = 242.0-ans     #V\n",
    "print \"Current fed at A is = \",Ia,\"A.\"\n",
    "print \"Current fed at B is = \",Ib,\"A.\"\n",
    "print \"Point of minimum potential from B is = \",distB,\"metres.\"\n",
    "print \"Voltage at minimum potential is = \",round(pot_M,2),\"V.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.17 ,Page No :- 1590"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage at B is =  236.9 V.\n",
      "Voltage at C is =  235.98 V.\n",
      "Voltage at D is =  237.45 V.\n"
     ]
    }
   ],
   "source": [
    "#A 400-metre ring distributor has loads as shown in Fig. 40.29(a) where distances are in metres.The resistance\n",
    "#of each conductor is 0.2 ohm per 1000 metres and the loads tapped off at points B,C,D are as shown.If the\n",
    "#distributor is fed at A,find voltages at B,C and D.\n",
    "#################################################################################################################\n",
    "\n",
    "#Given\n",
    "\n",
    "res = 0.2/1000   #ohm/m\n",
    "V_a = 240.0       #V\n",
    "#loads and positions\n",
    "i_b = 100.0  #A\n",
    "i_c = 70.0   #A\n",
    "i_d = 50.0   #A\n",
    "l_ab = 60.0   #m\n",
    "l_bc = 80.0   #m\n",
    "l_cd = 90.0   #m\n",
    "l_da = 70.0   #m\n",
    "\n",
    "#total drop ->70i + 90(i-50)+80(i-120)+60(i-220)=0\n",
    "cur_i = (l_cd*i_d + l_bc*(i_d+i_c) + l_ab*(i_d+i_c+i_b))/(l_ab+l_bc+l_cd+l_da)\n",
    "#drops in different sections\n",
    "drop_da = 2*cur_i*l_da*res\n",
    "drop_cd = 2*(cur_i-i_d)*l_cd*res\n",
    "drop_bc = 2*abs(cur_i-i_d-i_c)*l_bc*res\n",
    "drop_ab = 2*abs(cur_i-i_d-i_c-i_b)*l_ab*res\n",
    "\n",
    "#voltages at different points\n",
    "V_d = V_a - drop_da\n",
    "V_c = V_d - drop_cd\n",
    "V_b = V_a - drop_ab\n",
    "print \"Voltage at B is = \",round(V_b,2),\"V.\"\n",
    "print \"Voltage at C is = \",round(V_c,2),\"V.\"\n",
    "print \"Voltage at D is = \",round(V_d,2),\"V.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.18 ,Page No :- 1591"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage at B is =  394.2 V.\n",
      "Voltage at C is =  393.42 V.\n",
      "Current in section BC is =  43.33 A.\n"
     ]
    }
   ],
   "source": [
    "#In a direct current ring main,a voltage of 400V is maintained at A.At B,500 metres away from A,a load of 150A is taken\n",
    "#and at C,300 metres from B,a load of 200A is taken.The distance between A and C is 700 metres.The resistance of each\n",
    "#conductor of the mains is 0.03ohm per 1000 metres.Find the voltage at B and C and also find the current in the section BC.\n",
    "##############################################################################################################################\n",
    "\n",
    "#Given\n",
    "V_a = 400.0    #V\n",
    "res = 0.03/1000   #ohm/m\n",
    "#loads and positions\n",
    "i_b = 150.0    #A\n",
    "i_c = 200.0    #A\n",
    "l_ab = 500.0   #m\n",
    "l_bc = 300.0   #m\n",
    "l_ca = 700.0   #m\n",
    "\n",
    "#total drop-> 500i + 300(i-150) + 700(i-350) = 0\n",
    "cur_i = (l_bc*i_b + l_ca*(i_b+i_c))/(l_ab+l_bc+l_ca)\n",
    "#current in different sections\n",
    "cur_ab = cur_i\n",
    "cur_bc = cur_i-i_b\n",
    "cur_ca = abs(cur_bc-i_c)\n",
    "#drops in different sections\n",
    "drop_ab = 2*cur_ab*l_ab*res\n",
    "drop_bc = 2*cur_bc*l_bc*res\n",
    "#voltages in different sections\n",
    "V_b = V_a-drop_ab\n",
    "V_c = V_b-drop_bc\n",
    "print \"Voltage at B is = \",round(V_b,2),\"V.\"\n",
    "print \"Voltage at C is = \",round(V_c,2),\"V.\"\n",
    "print \"Current in section BC is = \",round(cur_bc,2),\"A.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.19 ,Page No :- 1591"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current in AB,BC,CD,DE,EA is 29.04 A, 19.04 A, 0.96 A, 30.96 A, 40.96 A respectively.\n",
      "\n",
      "Voltage at B,C,D,E is 217.1 V, 216.14 V, 216.15 V, 216.93 V respectively\n",
      "\n",
      "Current in AB,BC,DE,CE,EA is 27.72 A, 17.72 A, 32.28 A, 9.76 A, 42.28 A respectively.\n",
      "\n",
      "Voltage at B,C,D,E is 217.23 V, 216.34 V, 216.02 V, 216.83 V respectively\n"
     ]
    }
   ],
   "source": [
    "#A d.c ring main ABCDE is fed at point A from a 220-V supply and the resistances(including both lead and return)\n",
    "#of the various sections are as follows(in ohms):AB=0.1;BC=0.05;CD=0.01;DE=0.025 and EA=0.075.The main supplies\n",
    "#loads of 10A at B; 20A at C; 30A at D and 10A at E.Find the magnitude and direction of the current flowing in each\n",
    "#section and the voltage at each load point.\n",
    "#If the points C and E are further linked together by a conductor of 0.05 ohm resistance and the output currents\n",
    "#from the mains remain unchanged,find the new distribution of the current and voltage in the network.\n",
    "#####################################################################################################################\n",
    "\n",
    "#Given\n",
    "\n",
    "V_a = 220.0      #V\n",
    "#resistances of different sections\n",
    "r_ab = 0.1      #ohm\n",
    "r_bc = 0.05     #ohm\n",
    "r_cd = 0.01     #ohm\n",
    "r_de = 0.025    #ohm\n",
    "r_ea = 0.075    #ohm\n",
    "#loads\n",
    "i_b = 10.0    #A\n",
    "i_c = 20.0    #A\n",
    "i_d = 30.0    #A\n",
    "i_e = 10.0    #A\n",
    "#total drop -> 0.1i + 0.05(i-10) + 0.01(i-30) + 0.025(i-60) + 0.075(i-70)=0\n",
    "cur_i = (r_bc*i_b + r_cd*(i_b+i_c) + r_de*(i_b+i_c+i_d) + r_ea*(i_b+i_c+i_d+i_e))/(r_ab+r_bc+r_cd+r_de+r_ea)\n",
    "#current in different sections\n",
    "cur_ab = cur_i\n",
    "cur_bc = cur_ab-i_b\n",
    "cur_cd = cur_bc-i_c\n",
    "cur_de = cur_cd-i_d\n",
    "cur_ea = cur_de-i_e\n",
    "\n",
    "#drops in different sections\n",
    "drop_ab = cur_ab*r_ab\n",
    "drop_bc = cur_bc*r_bc\n",
    "drop_de = abs(cur_de)*r_de\n",
    "drop_ea = abs(cur_ea)*r_ea\n",
    "#voltages at different points\n",
    "V_b = V_a - drop_ab\n",
    "V_c = V_b - drop_bc\n",
    "V_e = V_a - drop_ea\n",
    "V_d = V_e - drop_de\n",
    "print \"Current in AB,BC,CD,DE,EA is\",round(cur_ab,2),\"A,\",round(cur_bc,2),\"A,\",round(abs(cur_cd),2),\"A,\",round(abs(cur_de),2),\"A,\",round(abs(cur_ea),2),\"A respectively.\" \n",
    "print \"\"\n",
    "print \"Voltage at B,C,D,E is\",round(V_b,2),\"V,\",round(V_c,2),\"V,\",round(V_d,2),\"V,\",round(V_e,2),\"V respectively\"\n",
    "print \"\"\n",
    "#part-2\n",
    "#Potential difference between end points of interconnector(CE)\n",
    "V_ce = V_e-V_c\n",
    "#Resistance between CE ,as shown in figure\n",
    "r1 = r_ab+r_bc+r_ea\n",
    "r2 = r_de + r_cd\n",
    "res_ce = r1*r2/(r1+r2)+ 0.05\n",
    "\n",
    "#Current in interconnector [I = V/R Ohm's Law]\n",
    "cur_ce = V_ce/res_ce\n",
    "#Current goes from E to C as E is at higher potential.\n",
    "\n",
    "#The current in other sections will also change.\n",
    "#let us assume i1 along ED, voltage round the closed mesh EDC is zero.\n",
    "#total drop -> -0.025*i1-0.01*(i1-30)+0.05*9.75 = 0\n",
    "\n",
    "cur_i1 = (0.05*cur_ce + r_cd*i_d)/(r_cd+r_de)\n",
    "\n",
    "current_ea = i_e+cur_i1+cur_ce\n",
    "current_ab = (i_b+i_c+i_d+i_e)-current_ea\n",
    "current_bc = current_ab-i_b\n",
    "current_de = current_ea-i_e\n",
    "#new drops\n",
    "drop_ab = current_ab*r_ab\n",
    "drop_bc = current_bc*r_bc\n",
    "drop_ea = current_ea*r_ea\n",
    "drop_de = current_de*r_de\n",
    "\n",
    "#new potentials\n",
    "V_b = V_a - drop_ab\n",
    "V_c = V_b - drop_bc\n",
    "V_e = V_a - drop_ea\n",
    "V_d = V_e - drop_de\n",
    "\n",
    "print \"Current in AB,BC,DE,CE,EA is\",round(current_ab,2),\"A,\",round(current_bc,2),\"A,\",round(current_de,2),\"A,\",round(cur_ce,2),\"A,\",round(current_ea,2),\"A respectively.\"\n",
    "print \"\"\n",
    "print \"Voltage at B,C,D,E is\",round(V_b,2),\"V,\",round(V_c,2),\"V,\",round(V_d,2),\"V,\",round(V_e,2),\"V respectively\"                                 \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.20 ,Page No :- 1594"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage across 3 ohm load is =  244.9 V.\n",
      "Voltage across 4 ohm load is =  247.9 V.\n"
     ]
    }
   ],
   "source": [
    "#In a 3-wire distribution system,the supply voltage is 250V on each side.The load on one side is a 3 ohm\n",
    "#resistance and on the other, a 4 ohm resistance.The resistance of each of the 3 conductors is 0.05 ohm.\n",
    "#Find the load voltages.\n",
    "#########################################################################################################\n",
    "\n",
    "import numpy as np\n",
    "#Given\n",
    "#Resistances\n",
    "res_1 = 3.0   #ohm\n",
    "res_2 = 4.0   #ohm\n",
    "res_con = 0.05 #ohm\n",
    "V_sup = 250.0  #V\n",
    "\n",
    "#Let the assumed directions of unknown currents be as shown in figure.\n",
    "#KVL for ABCD\n",
    "# (3+0.05)x + 0.05(x-y) = 250  -------------- eqn 1\n",
    "a = res_1 + 2*res_con\n",
    "b = -(res_con)\n",
    "#KVL for DCEFD\n",
    "# 0.05(y-x) + (4+0.05)y = 250  -------------- eqn 2\n",
    "c = res_2+ 2*res_con       \n",
    "#Solving eqn 1 and eqn2\n",
    "m = [[a,b],[b,c]]\n",
    "n = [V_sup,V_sup]\n",
    "soln = np.linalg.solve(m,n)            #soln is array with its elements[x,y]\n",
    "#Calculating the load voltages\n",
    "#V1 = 250-0.05*x-0.05(x-y)\n",
    "vol1 = V_sup - res_con*soln[0]-res_con*(soln[0]-soln[1])    #V\n",
    "#V2 = 250 + 0.05(x-y)- 0.05y\n",
    "vol2 = V_sup + res_con*(soln[0]-soln[1]) - res_con*soln[1]  #V\n",
    "print \"Voltage across 3 ohm load is = \",round(vol1,1),\"V.\"\n",
    "print \"Voltage across 4 ohm load is = \",round(vol2,1),\"V.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.21 ,Page No :- 1594"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Potential Difference across AB is =  248.62 V.\n",
      "Potential Difference across QK is =  247.83 V.\n",
      "Potential Difference across CD is =  248.4 V.\n",
      "Potential Difference across FE is =  247.65 V.\n"
     ]
    }
   ],
   "source": [
    "#A 3-wire d.c distributor PQ,250 metres long,is supplied at end P at 500/250V and is loaded as under:\n",
    "#Positive side: 20A 150 metres from P ; 30A 250 metres from P.\n",
    "#Negative side: 24A 100 metres from P ; 36A 220 metres from P.\n",
    "#The resistance of each outer wire is 0.02 ohm per 100 metres and the cross-section of the middle wire\n",
    "#is one-half of the outer.Find the voltage across each load point.\n",
    "##########################################################################################################\n",
    "\n",
    "#Given\n",
    "V_PN = 250.0 #V\n",
    "V_NR = 250.0 #V\n",
    "res_out = 0.02/100      #ohm/m\n",
    "res_mid = 2*res_out       #ohm/m  (Area of middle wire is half.As, R = rho*l/A .Therefore,Resistance doubles)\n",
    "\n",
    "#Given Currents\n",
    "i_ab = 20.0  #A\n",
    "i_qk = 30.0  #A\n",
    "i_cd = 24.0  #A\n",
    "i_fe = 36.0  #A\n",
    "\n",
    "#Currents in different sections\n",
    "i_pa = i_ab+i_qk   #A\n",
    "i_aq = i_qk        #A\n",
    "i_fk = i_qk        #A\n",
    "i_bf = i_fe-i_qk   #A\n",
    "i_bc = i_ab-i_bf   #A\n",
    "i_cn = i_cd-i_bc   #A\n",
    "i_de = i_fe        #A\n",
    "i_dr = i_cd+i_fe   #A\n",
    "\n",
    "\n",
    "#lengths of different sections\n",
    "l_pa = 150.0 #m\n",
    "l_aq = 100.0 #m\n",
    "l_kf = 250.0-220.0 #m\n",
    "l_bc = 150.0-100.0 #m\n",
    "l_bf = 220.0-150.0 #m\n",
    "l_cn = 100.0 #m\n",
    "l_de = 220.0-100.0 #m\n",
    "l_dr = 100.0  #m\n",
    "\n",
    "#Resistances of different sections\n",
    "r_pa = l_pa*res_out #ohm\n",
    "r_aq = l_aq*res_out #ohm\n",
    "r_kf = l_kf*res_mid #ohm\n",
    "r_bc = l_bc*res_mid #ohm\n",
    "r_bf = l_bf*res_mid #ohm\n",
    "r_cn = l_cn*res_mid #ohm\n",
    "r_de = l_de*res_out #ohm\n",
    "r_dr = l_dr*res_out #ohm\n",
    "\n",
    "#Drop across different sections\n",
    "drop_pa = r_pa*i_pa #V\n",
    "drop_aq = r_aq*i_aq #V\n",
    "drop_kf = r_kf*i_fk #V\n",
    "drop_bc = r_bc*i_bc #V\n",
    "drop_bf = r_bf*i_bf #V\n",
    "drop_cn = r_cn*i_cn #V\n",
    "drop_de = r_de*i_de #V\n",
    "drop_dr = r_dr*i_dr #V\n",
    "\n",
    "#Voltages across different sections\n",
    "vol_ab = V_PN - drop_pa - drop_bc + drop_cn       #V\n",
    "vol_qk = vol_ab - drop_aq - drop_kf + drop_bf     #V\n",
    "vol_cd = V_NR - drop_cn - drop_dr                 #V  \n",
    "vol_fe = vol_cd + drop_bc - drop_bf - drop_de     #V\n",
    "\n",
    "print \"Potential Difference across AB is = \",round(vol_ab,2),\"V.\"\n",
    "print \"Potential Difference across QK is = \",round(vol_qk,2),\"V.\"\n",
    "print \"Potential Difference across CD is = \",round(vol_cd,2),\"V.\"\n",
    "print \"Potential Difference across FE is = \",round(vol_fe,2),\"V.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.22 ,Page No :- 1597"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total load on main generator is =  155.0 kW.\n",
      "Load on Balancer 1 is =  22.5 kW.\n",
      "Load on Balancer 2 is =  27.5 kW.\n"
     ]
    }
   ],
   "source": [
    "#A d.c 3-wire system with 500-V between outers has lighting load of 100kW on the positive and 50kW on the\n",
    "#negative side.If,at this loading,the balancer machines have each a loss of 2.5kW,Calculate the kW loading\n",
    "#of each balancer machine and the total load on the system.\n",
    "###########################################################################################################\n",
    "\n",
    "#Given\n",
    "V_out = 500.0  #V\n",
    "load_p = 100.0 #kW (positive side)\n",
    "load_n = 50.0  #KW (negative side)\n",
    "load_b = 2.5   #kW  (balancer machine)\n",
    "#total load on main generator\n",
    "load_tot = load_p + load_n + 2*load_b  #kW\n",
    "#Output current of main generator\n",
    "cur_out = load_tot*1000/V_out   #W/V->A\n",
    "#load current on positive side\n",
    "cur_p = load_p*1000/(V_out/2)  #A\n",
    "#load current on negative side\n",
    "cur_n = load_n*1000/(V_out/2)  #A\n",
    "#Current through neutral(Out of balance)\n",
    "cur_o = cur_p-cur_n     #A\n",
    "\n",
    "#Currents of balancer\n",
    "cur_b1 = cur_p-cur_out  #A\n",
    "cur_b2 = cur_o - cur_b1 #A\n",
    "\n",
    "#Load on balancer\n",
    "load_b1 = (V_out/2)*cur_b1/1000    #kW\n",
    "load_b2 = (V_out/2)*cur_b2/1000    #kW\n",
    "\n",
    "print \"Total load on main generator is = \",round(load_tot,2),\"kW.\"\n",
    "print \"Load on Balancer 1 is = \",round(load_b1,2),\"kW.\"\n",
    "print \"Load on Balancer 2 is = \",round(load_b2,2),\"kW.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.23 ,Page No :- 1598"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total load on main generator is =  1216.0 kW.\n",
      "Current through Balancer 1 is =  168.0 A.\n",
      "Current through Balancer 2 is =  232.0 A.\n"
     ]
    }
   ],
   "source": [
    "#In a 500/250-V d.c 3-wire system,there is a current of 2000A on the +ve side, 1600A on the negative side\n",
    "#and a load of 300 kW across the outers.The loss in each balancer set is 8 kW.Calculate the current in each\n",
    "#armature of the balancer set and total load on the main generator.\n",
    "#############################################################################################################\n",
    "\n",
    "#Given\n",
    "V_out    = 500.0  #V\n",
    "cur_p    = 2000.0 #A (current on positive side)\n",
    "cur_n    = 1600.0 #A (current on negative side)\n",
    "load_ext = 300.0 #kW (across outers)\n",
    "load_b   = 8.0   #kW  (loss in balancer set)\n",
    "#loading on positive side\n",
    "load_p = (cur_p*(V_out/2))/1000  #kW\n",
    "#loading on negative side\n",
    "load_n = (cur_n*(V_out/2))/1000  #kW\n",
    "#Total loading on main generator\n",
    "load_tot = load_p + load_n + 2*load_b + load_ext   #kW\n",
    "\n",
    "#current on main generator -> I = W/V\n",
    "cur_tot = load_tot*1000/V_out     #A\n",
    "\n",
    "#current through neutral(out of balance)\n",
    "cur_o = cur_p-cur_n    #A\n",
    "\n",
    "#current through external resistance\n",
    "cur_ext = load_ext*1000/V_out    #A\n",
    "\n",
    "#current through balancer sets\n",
    "cur_b1 = (cur_p+cur_ext)-cur_tot      #A\n",
    "cur_b2 = cur_o - cur_b1               #A\n",
    "\n",
    "print \"Total load on main generator is = \",round(load_tot,2),\"kW.\"\n",
    "print \"Current through Balancer 1 is = \",round(cur_b1,2),\"A.\"\n",
    "print \"Current through Balancer 2 is = \",round(cur_b2,2),\"A.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.24 ,Page No :- 1598"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current supplied by generator is =  7000.0 A.\n",
      "Current in positive side is =  6000.0 A.\n",
      "Current in negative side is =  8000.0 A.\n",
      "Current in neutral is =  2000.0 A.\n",
      "Current through armature 1 is =  1000.0 A.\n",
      "Current through armature 2 is =  1000.0 A.\n"
     ]
    }
   ],
   "source": [
    "#On a 3-wire d.c distribution system with 500V between outers,there is a load of 1500kW on the positive\n",
    "#side and 2000 kW on the negative side.Calculate the current in the neutral and in each of the balancer\n",
    "#armatures and the total current supplied by the generator.Neglect losses.\n",
    "##########################################################################################################\n",
    "\n",
    "#Given\n",
    "V_out = 500.0    #V\n",
    "load_p = 1500.0  #kW   (load on positive side)\n",
    "load_n = 2000.0  #kW   (load on negative side)\n",
    "#total loading on main generator\n",
    "load_tot = load_p + load_n    #kW\n",
    "#current supplied by generator\n",
    "cur_tot = load_tot*1000/V_out    #A\n",
    "#current on positive side\n",
    "cur_p = load_p*1000/(V_out/2)    #A\n",
    "#current on negative side\n",
    "cur_n = load_n*1000/(V_out/2)    #A\n",
    "#current in neutral(out of balance)\n",
    "cur_o = abs(cur_p-cur_n)   #A\n",
    "#current through armatures\n",
    "cur_b1 = cur_tot-cur_p  #A\n",
    "cur_b2 = cur_o-cur_b1   #A\n",
    "\n",
    "print \"Current supplied by generator is = \",cur_tot,\"A.\"\n",
    "print \"Current in positive side is = \",cur_p,\"A.\"\n",
    "print \"Current in negative side is = \",cur_n,\"A.\"\n",
    "print \"Current in neutral is = \",cur_o,\"A.\"\n",
    "print \"Current through armature 1 is = \",cur_b1,\"A.\"\n",
    "print \"Current through armature 2 is = \",cur_b2,\"A.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.25 ,Page No :- 1599"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current in balancer set 1 is =  22.0 A.\n",
      "Current in balancer set 2 is =  28.0 A.\n",
      "Output of main generator is =  119.5 kW.\n"
     ]
    }
   ],
   "source": [
    "#A 125/250 V,3-wire distributor has an out-of-balance current of 50 A and larger load of 500 A.The balancer\n",
    "#set has a loss of 375 W in each machine.Calculate the current in each of the balancer machines and output\n",
    "#of main generator.\n",
    "############################################################################################################\n",
    "\n",
    "#Given\n",
    "V_out = 250.0    #V\n",
    "#Currents\n",
    "cur_p = 500.0  #A\n",
    "cur_o = 50.0   #A\n",
    "cur_n = cur_p - cur_o  #A\n",
    "#larger Load\n",
    "load_p = cur_p*(V_out/2)/1000   #kW\n",
    "#smaller Load\n",
    "load_n = cur_n*(V_out/2)/1000   #kW\n",
    "#Balancer loss\n",
    "loss_b = 2*375.0/1000     #kW\n",
    "#total load on generator\n",
    "load_tot = load_p + load_n + loss_b\n",
    "#current from main generator -> VI = W\n",
    "cur_tot = load_tot*1000/V_out   #A\n",
    "\n",
    "#Current in balancer sets\n",
    "cur_b1 = cur_p - cur_tot     #A\n",
    "cur_b2 = cur_o - cur_b1      #A\n",
    "print \"Current in balancer set 1 is = \",cur_b1,\"A.\"\n",
    "print \"Current in balancer set 2 is = \",cur_b2,\"A.\"\n",
    "print \"Output of main generator is = \",load_tot,\"kW.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.26 ,Page No :- 1599"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total load on main generator is =  1210.0 kW.\n",
      "Load on Balancer set 1 is =  20.0 kW.\n",
      "Load on balancer set 2 is =  30.0 kW.\n"
     ]
    }
   ],
   "source": [
    "#The load on d.c 3-wire system with 500 V between outers consists of lighting current of 1500 A on the\n",
    "#positive side and 1300 A on the negative side while motors connected across the outers absorb 500kW.\n",
    "#Assuming that at this loading,the balancer machines have each a loss of 5kW,calculate the load on the\n",
    "#main generator and on each of the balancer machines.\n",
    "##########################################################################################################\n",
    "\n",
    "#Given\n",
    "cur_p = 1500.0   #A\n",
    "cur_n = 1300.0   #A\n",
    "V_out = 500.0    #V\n",
    "load_ext = 500.0   #kW\n",
    "loss_b = 2*5.0     #kW\n",
    "\n",
    "#current through external load\n",
    "cur_ext = load_ext*1000/V_out   #A\n",
    "#larger load\n",
    "load_p = cur_p*(V_out/2)/1000   #kW\n",
    "#smaller load\n",
    "load_n = cur_n*(V_out/2)/1000   #kW\n",
    "#total load on generator\n",
    "load_tot = load_p + load_n + loss_b + load_ext   #kW\n",
    "#current from generator -> VI = W\n",
    "cur_tot = load_tot*1000/V_out     #A\n",
    "#current through neutral(out of balance)\n",
    "cur_o = cur_p-cur_n      #A\n",
    "#current through balancer sets\n",
    "cur_b1 = (cur_p+cur_ext)-cur_tot   #A\n",
    "cur_b2 = cur_o-cur_b1              #A\n",
    "#load of balancer sets\n",
    "load_b1 = cur_b1*(V_out/2)/1000    #kW\n",
    "load_b2 = cur_b2*(V_out/2)/1000    #kW\n",
    "\n",
    "print \"Total load on main generator is = \",load_tot,\"kW.\"\n",
    "print \"Load on Balancer set 1 is = \",load_b1,\"kW.\"\n",
    "print \"Load on balancer set 2 is = \",load_b2,\"kW.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.27 ,Page No :- 1599"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage across Balancer 1 is =  230.0 A.\n",
      "Voltage across Balancer 2 is =  250.0 A.\n",
      "Load current on main generator is =  1110.0 A.\n"
     ]
    }
   ],
   "source": [
    "#A d.c 3-wire system with 480 V across outers supplies 1200 A on the positive and 1000 A on the negative side.\n",
    "#The balancer machines have each an armature resistances of 0.1W and take 10 A on no-load.Find\n",
    "#(a)the voltage across each balancer and\n",
    "#(b)the total load on the main generator and the current loading of each balancer machine.\n",
    "#The balancer field windings are in series across the outers\n",
    "################################################################################################################\n",
    "\n",
    "#Given\n",
    "V_out = 480.0   #V\n",
    "#currents\n",
    "cur_p = 1200.0  #A\n",
    "cur_n = 1000.0  #A\n",
    "cur_o = cur_p - cur_n  #A (out of balance)\n",
    "#armature resistance \n",
    "res_arm = 0.1    #ohm\n",
    "#no-load current\n",
    "cur_nold = 10.0   #A\n",
    "\n",
    "#Let us assume current Im flows through mtoring machine,then (200-Im) flows through generating machine.\n",
    "#Let Vg and Vm be potential difference of 2 machines.\n",
    "\n",
    "#Total losses in sets = no-load losses + Cu losses in two machines\n",
    "#loss_set = V_out*cur_nold  + 0.1*Im^2+ 0.1*(200-Im)^2\n",
    "#Vm*Im = Vg*Ig + loss_set\n",
    "#Now, Vm = Eb+Im*Ra           Vg = Eb-Ig*Ra\n",
    "Eb = V_out/2-res_arm*cur_nold\n",
    "\n",
    "#Therefore, Vm = 239 + Im*0.1              and Vg = 239 - (200-Im)*0.1\n",
    "#Hence,Equation is \n",
    "#(239+0.1*Im)*Im = [239 - (200-Im)*0.1]*(200-Im) + loss_set\n",
    "#Simplified ->  239Im = 239*(200-Im)+4800\n",
    "\n",
    "#Solving this equation\n",
    "from sympy import Eq, var, solve\n",
    "var('Im')    \n",
    "eq = Eq(Eb*(2*Im-cur_o),V_out*cur_nold)\n",
    "Im =  solve(eq)\n",
    "Im = int(Im[0])\n",
    "Ig = cur_o-Im\n",
    "#Voltage across balancers\n",
    "\n",
    "Vm = Eb + Im*res_arm     #V\n",
    "Vg = Eb - Ig*res_arm     #V \n",
    "\n",
    "#Load on main generator\n",
    "cur_load = cur_p - Ig    #A\n",
    "print \"Voltage across Balancer 1 is = \",round(Vg,2),\"A.\"\n",
    "print \"Voltage across Balancer 2 is = \",round(Vm,2),\"A.\"\n",
    "print \"Load current on main generator is = \",round(cur_load,2),\"A.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.28 ,Page No :- 1600"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage on positive side is =  283.0 V.\n",
      "Voltage on negative side is =  177.0 V.\n"
     ]
    }
   ],
   "source": [
    "#A d.c 3-wire system with 460V between outers supplies 250kW on the positive and 400kW on the negative side,\n",
    "#the voltages being balanced.Calculate the voltage on the positive and negative side,the voltages being balanced.\n",
    "#Calculate the voltage on the positive and negative sides repectively,if the neutral wire becomes disconnected\n",
    "#from balancer set.\n",
    "#################################################################################################################\n",
    "\n",
    "#Given\n",
    "V_mid = 230.0   #V\n",
    "V_out = 460.0   #V\n",
    "#loads\n",
    "load_p = 250.0  #kW\n",
    "load_n = 400.0  #kW\n",
    "#resistance on positive side -> (V^2/R) = W\n",
    "res_p = (V_mid*V_mid)/(load_p*1000)    #ohm\n",
    "\n",
    "#resistance on negative side -> (V^2/R) = W\n",
    "res_n = (V_mid*V_mid)/(load_n*1000)    #ohm\n",
    "\n",
    "#Voltages after disconnecting balancer set\n",
    "vol_p = (res_p/(res_p+res_n))*V_out      #V\n",
    "vol_n = V_out - vol_p        #V\n",
    "\n",
    "print \"Voltage on positive side is = \",round(vol_p),\"V.\"\n",
    "print \"Voltage on negative side is = \",round(vol_n),\"V.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 40.29 ,Page No :- 1601"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Terminal potential difference of the booster is =  180.0 V.\n",
      "Output of booster is =  21.6 kW.\n"
     ]
    }
   ],
   "source": [
    "#A 2-wire system has the voltage at the supply end maintained at 500.The line is 3 km long.If the full-load\n",
    "#current is 120 A,what must be the booster voltage and output in order that the far end voltage may also be 500 V.\n",
    "#Take the resistance of the cable at the working temperature as 0.5ohm/kilometre.\n",
    "####################################################################################################################\n",
    "\n",
    "#Total resistance of line\n",
    "res_tot = 0.5*3     #ohm\n",
    "#Full load current\n",
    "cur_full = 120.0    #A\n",
    "\n",
    "#drop in the line-> V=IR\n",
    "drop = res_tot*cur_full   #V\n",
    "\n",
    "#Output of booster ->VI = W\n",
    "output = drop*cur_full/1000   #kW\n",
    "\n",
    "print \"Terminal potential difference of the booster is = \",drop,\"V.\"\n",
    "print \"Output of booster is = \",round(output,2),\"kW.\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}