summaryrefslogtreecommitdiff
path: root/Electrical_Circuit_Theory_And_Technology/chapter_31-checkpoint.ipynb
blob: 5c1fd9c0b748a0cc73df16cee73ca839a9ad6e6b (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
{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h1>Chapter 31: Mesh-current and nodal analysis</h1>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 1, page no. 546</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Use mesh-current analysis to determine the current flowing in \n",
      "#(a) the 5 ohm resistance, and (b) the 1 ohm resistance of the d.c. circuit\n",
      "from __future__ import division\n",
      "import math\n",
      "import numpy\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "V1  =  4;#  in  volts\n",
      "V2  =  5;#  in  volts\n",
      "R1  =  3;#  in  ohm\n",
      "R2  =  5;#  in  ohm\n",
      "R3  =  4;#  in  ohm\n",
      "R4  =  1;#  in  ohm\n",
      "R5  =  6;#  in  ohm\n",
      "R6  =  8;#  in  ohm\n",
      "\n",
      "#calculation:\n",
      " #The  mesh  currents  I1,  I2  and  I3  are  shown  in  Figure  31.2.  Using  Kirchhoff\u2019s  voltage  law  in  3  loops\n",
      " #three  eqns  obtained\n",
      " #(R1  +  R2)*I1  -  R2*I2  =  V1\n",
      " #-1*R2*I1  +  (R2  +  R3  +  R4  +  R5)*I2  -  R4*I3  =  0\n",
      " #  -1*R4*I2  +  (R4  +  R6)*I3  =  -1*V2\n",
      " #using  determinants\n",
      "d1  =  [[V1,  -1*R2,  0],[0,  (R2  +  R3  +  R4  +  R5),  -1*R4],[-1*V2,  -1*R4,  (R4  +  R6)]]\n",
      "D1  =  numpy.linalg.det(d1)\n",
      "d2  =  [[(R1  +  R2),  V1,  0],[-1*R2,  0,  -1*R4],[0,  -1*V2,  (R4  +  R6)]]\n",
      "D2  =  numpy.linalg.det(d2)\n",
      "d3  =  [[(R1  +  R2),  -1*R2,  V1],[-1*R2,  (R2  +  R3  +  R4  +  R5),  0],[0,  -1*R4,  -1*V2]]\n",
      "D3  =  numpy.linalg.det(d3)\n",
      "d  =  [[(R1  +  R2),  -1*R2,  0],[-1*R2,  (R2  +  R3  +  R4  +  R5),  -1*R4],[0,  -1*R4,  (R4  +  R6)]]\n",
      "D  =  numpy.linalg.det(d)\n",
      "I1  =  D1/D\n",
      "I2  =  D2/D\n",
      "I3  =  D3/D  \n",
      "IR2  =  I1  -  I2\n",
      "IR4  =  I2  -  I3\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  (a)current  in  the  5  ohm  resistance  is  \",round(IR2,2),\"  A\"\n",
      "print  \"\\n  (b)current  in  the  1  ohm  resistance  is  \",round(IR4,2),\"  A\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  (a)current  in  the  5  ohm  resistance  is   0.44   A\n",
        "\n",
        "  (b)current  in  the  1  ohm  resistance  is   0.69   A"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 2, page no. 547</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#determine, using mesh-current analysis, \n",
      "#(a) the mesh currents I1 and I2 \n",
      "#(b) the current flowing in the capacitor,\n",
      "#(c) the active power delivered by the voltage source.\n",
      "from __future__ import division\n",
      "import math\n",
      "import numpy\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "rv  =  100;#  in  volts\n",
      "thetav  =  0;#  in  degrees\n",
      "R1  =  5;#  in  ohm\n",
      "R2  =  -1j*4;#  in  ohm\n",
      "R3  =  4;#  in  ohm\n",
      "R4  =  3j;#  in  ohm\n",
      "\n",
      " #calculation:\n",
      " #voltages\n",
      "V  =  rv*math.cos(thetav*math.pi/180)  +  1j*rv*math.sin(thetav*math.pi/180)\n",
      " #Currents  I1,  I2  with  their  directions  are  shown  in  Figure  31.03.\n",
      " #Two  loops  are  chosen.  The  choice  of  loop  directions  is  arbitrary.\n",
      " #using  kirchoff  rule  in  2  loops\n",
      " #two  eqns  obtained\n",
      " #(R1  +  R2)*I1  -  R2*I2  =  V\n",
      " #-1*R2*I1  +  (R3  +  R2  +  R4)*I2  =  0\n",
      " #using  determinants\n",
      "d1  =  [[V,  -1*R2],[0,  (R3  +  R2  +  R4)]]\n",
      "D1  =  numpy.linalg.det(d1)\n",
      "d2  =  [[(R1  +  R2),  V],[-1*R2,  0]]\n",
      "D2  =  numpy.linalg.det(d2)\n",
      "d  =  [[(R1  +  R2),  -1*R2],[-1*R2,  (R3  +  R2  +  R4)]]\n",
      "D  =  numpy.linalg.det(d)\n",
      "I1  =  D1/D\n",
      "I2  =  D2/D\n",
      "I1mag  =  abs(I1)\n",
      " #Current  flowing  in  capacitor\n",
      "Ic  =  I1  -  I2\n",
      " #Source  power  P\n",
      "phi  =  cmath.phase(complex(I1.real,I1.imag))\n",
      "P  =  V*I1mag*math.cos(phi)\n",
      "Icmag  =  abs(Ic)\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"(a)current,I1 is  \",round(I1.real,2),\"  +  (\",round(  I1.imag,2),\")i  A,  current,  I2  is\",round(I2.real,2),\"  +  (\",round(I2.imag,2),\")i  A\"\n",
      "print  \"(b)current  in  the  capacitor  is  \",round(Icmag,2),\"  A\"\n",
      "print  \"(c)Source  power  P  is  \",round(abs(P),2),\"  W\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "(a)current,I1 is   10.17   +  ( 3.55 )i  A,  current,  I2  is 5.73   +  ( -8.74 )i  A\n",
        "(b)current  in  the  capacitor  is   13.06   A\n",
        "(c)Source  power  P  is   1017.06   W\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 3, page no. 548</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Determine the value of the line currents IR, IY and IB using mesh-current analysis\n",
      "from __future__ import division\n",
      "import math\n",
      "import numpy\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "rv1  =  415;#  in  volts\n",
      "rv2  =  415;#  in  volts\n",
      "thetav1  =  120;#  in  degrees\n",
      "thetav2  =  0;#  in  degrees\n",
      "R  =  3  +  4j;#  in  ohm\n",
      "\n",
      " #calculation:\n",
      " #voltages\n",
      "V1  =  rv1*math.cos(thetav1*math.pi/180)  +  1j*rv1*math.sin(thetav1*math.pi/180)\n",
      "V2  =  rv2*math.cos(thetav2*math.pi/180)  +  1j*rv2*math.sin(thetav2*math.pi/180)\n",
      " #Two  mesh  currents  I1  and  I2  are  chosen  as  shown  in  Figure  31.4.\n",
      " #Two  loops  are  chosen.  The  choice  of  loop  directions  is  arbitrary.\n",
      " #using  kirchoff  rule  in  2  loops\n",
      " #two  eqns  obtained\n",
      " #2*R*I1  -  R*I2  =  V1\n",
      " #-1*R*I1  +  2*R*I2  =  V2\n",
      " #using  determinants\n",
      "d1  =  [[V1,  -1*R],[V2, 2*R]]\n",
      "D1  =  numpy.linalg.det(d1)\n",
      "d2  =  [[2*R, V1],[-1*R, V2]]\n",
      "D2  =  numpy.linalg.det(d2)\n",
      "d  =  [[2*R, -1*R],[-1*R,  2*R]]\n",
      "D  =  numpy.linalg.det(d)\n",
      "I1  =  D1/D\n",
      "I2  =  D2/D\n",
      "I1mag  =  abs(I1)\n",
      " #line  current  IR\n",
      "IR  =  I1\n",
      " #line  current  IB\n",
      "IB  =  -1*I2\n",
      " #line  current  IY\n",
      "IY  =  I2  -  I1\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"current, IR is\",round(IR.real,2),\"  +  (\",round(  IR.imag,2),\")i  A,  current,  IB  is\",round(IB.real,2),\"  +  (\",round(  IB.imag,2),\")i  A  and  current,  IY  is  \",round(IY.real,2),\"  +  (\",round(IY.imag,2),\")i  A\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "current, IR is 38.34   +  ( 28.75 )i  A,  current,  IB  is -44.07   +  ( 18.82 )i  A  and  current,  IY  is   5.73   +  ( -47.58 )i  A\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 4, page no. 551</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#determine the voltage VAB, by using nodal analysis.\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "ri  =  20;#  in  amperes\n",
      "thetai  =  0;#  in  degrees\n",
      "R1  =  10;#  in  ohm\n",
      "R2  =  3j;#  in  ohm\n",
      "R3  =  4;#  in  ohm\n",
      "R4  =  16;#  in  ohm\n",
      "\n",
      "#calculation:\n",
      " #current\n",
      "I  =  ri*math.cos(thetai*math.pi/180)  +  1j*ri*math.sin(thetai*math.pi/180)\n",
      " #Figure  31.8  contains  two  principal  nodes  (at  1  and  B)  and  thus  only  one  nodal  equation  is  required. \n",
      "    #B  is  taken  as  the  reference  node  and  the  equation  for  node  1  is  obtained  as  follows. \n",
      "    #Applying  Kirchhoff\u2019s  current  law  to  node  1  gives:\n",
      " #IX  +  IY  =  I\n",
      "V1  =  I/((1/R4)  +(1/(R2    +R3)))\n",
      "IY  =  V1/(R2  +  R3)\n",
      "VAB  =  IY*R3\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  voltage  VAB  is  \",round(VAB.real,2),\"  +  (\",round(  VAB.imag,2),\")i  V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  voltage  VAB  is   62.59   +  ( -9.39 )i  V"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5, page no. 552</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Determine the value of voltage VXY\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "rv1  =  8;#  in  volts\n",
      "rv2  =  8;#  in  volts\n",
      "thetav1  =  0;#  in  degrees\n",
      "thetav2  =  90;#  in  degrees\n",
      "R1  =  5;#  in  ohm\n",
      "R2  =  6j;#  in  ohm\n",
      "R3  =  4;#  in  ohm\n",
      "R4  =  3;#  in  ohm\n",
      "\n",
      "#calculation:\n",
      " #voltages\n",
      "V1  =  rv1*math.cos(thetav1*math.pi/180)  +  1j*rv1*math.sin(thetav1*math.pi/180)\n",
      "V2  =  rv2*math.cos(thetav2*math.pi/180)  +  1j*rv2*math.sin(thetav2*math.pi/180)\n",
      " #The  circuit  contains  no  principal  nodes.  \n",
      "    #However,  if  point  Y  is  chosen  as  the  reference  node  then  an  equation \n",
      "    #may  be  written  for  node  X  assuming  that  current  leaves  point  X  by  both  branches\n",
      "VX  =  ((V1/(R1  +  R3)  +  V2/(R2  +  R4))/(1/(R1  +  R3)  +  1/(R2  +  R4)))\n",
      "VXY  =  VX\n",
      "\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  voltage  VXY  = \",round(abs(VXY),2),\"/_\",round(cmath.phase(complex(VXY.real, VXY.imag))*180/math.pi,2),\"deg V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  voltage  VXY  =  9.12 /_ 52.13 deg V"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 6, page no. 553</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Use nodal analysis to determine the current flowing in each branch of the network\n",
      "from __future__ import division\n",
      "import math\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "rv1  =  100;#  in  volts\n",
      "rv2  =  50;#  in  volts\n",
      "thetav1  =  0;#  in  degrees\n",
      "thetav2  =  90;#  in  degrees\n",
      "R1  =  25;#  in  ohm\n",
      "R2  =  20;#  in  ohm\n",
      "R3  =  10;#  in  ohm\n",
      "\n",
      "#calculation:\n",
      " #voltages\n",
      "V1  =  rv1*math.cos(thetav1*math.pi/180)  +  1j*rv1*math.sin(thetav1*math.pi/180)\n",
      "V2  =  rv2*math.cos(thetav2*math.pi/180)  +  1j*rv2*math.sin(thetav2*math.pi/180)\n",
      " #There  are  only  two  principal  nodes  in  Figure  31.10  so  only  one  nodal  equation  is  required.  \n",
      "    #Node  2  is  taken  as  the  reference  node.\n",
      " #The  equation  at  node  1  is  I1  +  I2  +  I3  =  0\n",
      "Vn1  =  ((V1/R1  +  V2/R3)/(1/R1  +  1/R2  +  1/R3))\n",
      "I1  =  (Vn1  -  V1)/R1\n",
      "I2  =  Vn1/R2\n",
      "I3  =  (Vn1  -  V2)/R3\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  current,  I1  is  \",round(I1.real,2),\"  +  (\",round(  I1.imag,2),\")i  A, \\n current,  I2  is    \",round(I2.real,2),\"  +  (\",round( I2.imag,2),\")i  A \\n and  current,  I3  is  \",round(I3.real,2),\"  +  (\",round(I3.imag,2),\")i  A\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  current,  I1  is   -3.16   +  ( 1.05 )i  A, \n",
        " current,  I2  is     1.05   +  ( 1.32 )i  A \n",
        " and  current,  I3  is   2.11   +  ( -2.37 )i  A"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 7, page no. 554</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#determine (a) the voltage at nodes 1 and 2, (b) the current in the j4 ohm inductance,\n",
      "#(c) the current in the 5 ohm resistance, and (d) the magnitude of the active power dissipated in the 2.5ohm resistance.\n",
      "from __future__ import division\n",
      "import math\n",
      "import numpy\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "rv1  =  25;#  in  volts\n",
      "rv2  =  25;#  in  volts\n",
      "thetav1  =  0;#  in  degrees\n",
      "thetav2  =  90;#  in  degrees\n",
      "R1  =  2;#  in  ohm\n",
      "R2  =  -1j*4;#  in  ohm\n",
      "R3  =  5;#  in  ohm\n",
      "R4  =  4j;#  in  ohm\n",
      "R5  =  2.5;#  in  ohm\n",
      "\n",
      " #calculation:\n",
      " #voltages\n",
      "V1  =  rv1*math.cos(thetav1*math.pi/180)  +  1j*rv1*math.sin(thetav1*math.pi/180)\n",
      "V2  =  rv2*math.cos(thetav2*math.pi/180)  +  1j*rv2*math.sin(thetav2*math.pi/180)\n",
      " #The  equation  at  node  1\n",
      " #Vn1*(1/R1  +  1/R2  +  1/R3)  -  Vn2/R3  =  V1/R1\n",
      " #The  equation  at  node  2\n",
      " #Vn1*(-1/R3)  +  Vn2*(1/R4  +  1/R5  +  1/R3)  =  V2/R5\n",
      " #using  determinants\n",
      "d1  =  [[V1/R1,  -1/R3],[V2/R5,  (1/R4  +  1/R5  +  1/R3)]]\n",
      "D1  =  numpy.linalg.det(d1)\n",
      "d2  =  [[(1/R1  +  1/R2  +  1/R3),  V1/R1],[-1/R3,  V2/R5]]\n",
      "D2  =  numpy.linalg.det(d2)\n",
      "d  =  [[(1/R1  +  1/R2  +  1/R3),  -1/R3],[-1/R3,  (1/R4  +  1/R5  +  1/R3)]]\n",
      "D  =  numpy.linalg.det(d)\n",
      "Vn1  =  D1/D\n",
      "Vn2  =  D2/D\n",
      " #current  in  the  j4  ohm  inductance  is  given  by:\n",
      "I4  =  Vn2/R4\n",
      " #current  in  the  5  ohm  resistance  is  given  by:\n",
      "I3  =  (Vn1  -  Vn2)/R3\n",
      " #active  power  dissipated  in  the  2.5  ohm  resistor  is  given  by\n",
      "P5  =  R5*((Vn2  -  V2)/R5)**2\n",
      " #magnitude  of  the  active  power  dissipated\n",
      "P5mag  =  abs(P5)\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  (a)  the  voltage  at  nodes  1  and  2  are \",round(abs(Vn1),1),\"/_\",round(cmath.phase(complex(Vn1.real, Vn1.imag))*180/math.pi,2),\"deg  V  and \",round(abs(Vn2),1),\"/_\",round(cmath.phase(complex(Vn2.real, Vn2.imag))*180/math.pi,1),\"deg  V\"\n",
      "print  \"\\n  (b)the  current  in  the  j4  ohm inductance = \",round(abs(I4),2),\"/_\",round(cmath.phase(complex(I4.real, I4.imag))*180/math.pi,2),\"deg  A\"\n",
      "print  \"\\n  (c)the  current  in  the  5  ohm resistance  = \",round(abs(I3),2),\"/_\",round(cmath.phase(complex(I3.real, I3.imag))*180/math.pi,2),\"deg  A\"\n",
      "print  \"\\n  (d)  magnitude  of  the  active  power  dissipated  in  the  2.5  ohm  resistance  is  \",round(P5mag,2),\"  W\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  (a)  the  voltage  at  nodes  1  and  2  are  17.1 /_ -5.3 deg  V  and  15.8 /_ 93.2 deg  V\n",
        "\n",
        "  (b)the  current  in  the  j4  ohm inductance =  3.95 /_ 3.23 deg  A\n",
        "\n",
        "  (c)the  current  in  the  5  ohm resistance  =  4.99 /_ -44.06 deg  A\n",
        "\n",
        "  (d)  magnitude  of  the  active  power  dissipated  in  the  2.5  ohm  resistance  is   34.4   W"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 8, page no. 556</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#determine the voltage VXY using nodal analysis.\n",
      "from __future__ import division\n",
      "import math\n",
      "import numpy\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "ri  =  25;#  in  amperes\n",
      "thetai  =  0;#  in  degrees\n",
      "R1  =  4;#  in  ohm\n",
      "R2  =  3j;#  in  ohm\n",
      "R3  =  5;#  in  ohm\n",
      "R4  =  10j;#  in  ohm\n",
      "R5  =  20j;#  in  ohm\n",
      "\n",
      " #calculation:\n",
      " #current\n",
      "I  =  ri*math.cos(thetai*math.pi/180)  +  1j*ri*math.sin(thetai*math.pi/180)\n",
      " #Node  3  is  taken  as  the  reference  node.\n",
      " #At  node  1,\n",
      " #V1*(1/(R1  +  R2)  +  1/R3)  -  V2/R3  =  I\n",
      " #The  equation  at  node  2\n",
      " #V1*(-1/R3)  +  V2*(1/R4  +  1/R5  +  1/R3)  =  0\n",
      " #using  determinants\n",
      "d1  =  [[I,  -1/R3],[0 , (1/R4  +  1/R5  +  1/R3)]]\n",
      "D1  =  numpy.linalg.det(d1)\n",
      "d2  =  [[(1/(R1  +  R2)  +  1/R3),  I],[-1/R3,  0]]\n",
      "D2  =  numpy.linalg.det(d2)\n",
      "d  =  [[(1/(R1  +  R2)  +  1/R3),  -1/R3],[-1/R3,  (1/R4  +  1/R5  +  1/R3)]]\n",
      "D  =  numpy.linalg.det(d)\n",
      "V1  =  D1/D\n",
      "V2  =  D2/D\n",
      " #the  voltage  between  point  X  and  node  3  is\n",
      "VX  =  V1*R2/(R1  +  R2)\n",
      " #Thus  the  voltage\n",
      "VY  =  V2\n",
      "VXY  =  VX  -  VY\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  voltage  VXY  is  \",round(VXY.real,2),\"  +  (\",round(  VXY.imag,2),\")i  V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  voltage  VXY  is   -16.16   +  ( -15.05 )i  V"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 9, page no. 557</h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Use nodal analysis to determine the voltages at nodes 2 and 3 \n",
      "#determine the current flowing in the 2 ohm resistor and the power dissipated in the 3 ohm resistor.\n",
      "from __future__ import division\n",
      "import math\n",
      "import numpy\n",
      "import cmath\n",
      "#initializing  the  variables:\n",
      "V  =  8;#  in  volts\n",
      "R1  =  1;#  in  ohm\n",
      "R2  =  2;#  in  ohm\n",
      "R3  =  3;#  in  ohm\n",
      "R4  =  4;#  in  ohm\n",
      "R5  =  5;#  in  ohm\n",
      "R6  =  6;#  in  ohm\n",
      "\n",
      "#calculation:\n",
      " #In  Figure  31.13,  the  reference  node  is  shown  at  point  A.\n",
      " #At  node  1,\n",
      " #V1*(1/R1  +  1/R6  +  1/R5)  -  V2/R1  -  V3/R5  =  V/R5\n",
      " #The  equation  at  node  2\n",
      " #V1*(-1/R1)  +  V2*(1/R2  +  1/R1  +  1/R3)  -  V3/R3  =  0\n",
      " #At  node  3\n",
      " #  -  V1/R5  -  V2/R3  +  V3*(1/R4  +  1/R3  +  1/R5)  =  -1*V/R5\n",
      "#using  determinants\n",
      "d1  =  [[V/R5,  -1/R1,  -1/R5],[0, (1/R2  +  1/R1  +  1/R3),  -1/R3],[-1*V/R5, -1/R3,  (1/R4  +  1/R3  +  1/R5)]]\n",
      "D1  =  numpy.linalg.det(d1)\n",
      "d2  =  [[(1/R1  +  1/R6  +  1/R5),  V/R5,  -1/R5],[-1/R1,  0,  -1/R3],[-1/R5,  -1*V/R5,  (1/R4  +  1/R3  +  1/R5)]]\n",
      "D2  =  numpy.linalg.det(d2)\n",
      "d3  =  [[(1/R1  +  1/R6  +  1/R5),  -1/R1,  V/R5],[-1/R1,  (1/R2  +  1/R1  +  1/R3),  0],[-1/R5,  -1/R3,  -1*V/R5]]\n",
      "D3  =  numpy.linalg.det(d3)\n",
      "d  =[[(1/R1  +  1/R6  +  1/R5),  -1/R1,  -1/R5],[-1/R1,  (1/R2  +  1/R1  +  1/R3),  -1/R3],[-1/R5,  -1/R3,  (1/R4  +  1/R3  +  1/R5)]]\n",
      "D  =  numpy.linalg.det(d)\n",
      "Vn1  =  D1/D\n",
      "Vn2  =  D2/D\n",
      "Vn3  =  D3/D  \n",
      " #the  current  in  the  2  ohm  resistor\n",
      "I2  =  Vn2/R2\n",
      " #power  dissipated  in  the  3  ohm  resistance\n",
      "P3  =  R3*((Vn2  -  Vn3)/R3)**2\n",
      "\n",
      "\n",
      "#Results\n",
      "print  \"\\n\\n  Result  \\n\\n\"\n",
      "print  \"\\n  (a)current  through  2  ohm  resistor  is  \",round(I2,2),\"  A\"\n",
      "print  \"\\n  (b)power  dissipated  in  the  3  ohm  resistor  is  \",round(P3,2),\"  W\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "  Result  \n",
        "\n",
        "\n",
        "\n",
        "  (a)current  through  2  ohm  resistor  is   0.19   A\n",
        "\n",
        "  (b)power  dissipated  in  the  3  ohm  resistor  is   1.27   W\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}