Chapter 1: D C Circuit analysis

Example 1: pg 9

In [1]:
#pg 9
#calculate the current through all resistors
import numpy
from  numpy import matrix
from numpy.linalg import inv
# Given data
R1=4.;# in ohm
R2= 6.;# in ohm
R3= 2.;# in ohm
V1= 24.;# in V
V2= 12.;# in V
# Applying KVL in Mesh ABEFA, V1 = (R1+R3)*I1 - R3*I2    (i)
# Applying KVL in Mesh BCDEB, V2 = R3*I1 - (R2+R3)*I2   (ii)
#calculations
A= numpy.matrix([[(R1+R3), R3],[-R3, -(R2+R3)]]);# assumed
B= numpy.matrix([V1,V2]);# assumed
I= B*inv(A);# Solving equations by matrix multiplication
I1= I[0,0];# in A
I2= I[0,1];# in A
print "The current through 4 ohm resistor in A is",round(I1,2)
# current through 2 ohm resistor 
Ix= I1-I2;# in A
print "The current through 2 ohm resistor in A is",round(Ix,2)
print "The current through 6 ohm resistor in A is",round(I2,2)
print "That is ",round(abs(I2),2)," A current flows in 6 ohm resistor from C to B"
The current through 4 ohm resistor in A is 3.82
The current through 2 ohm resistor in A is 4.36
The current through 6 ohm resistor in A is -0.55
That is  0.55  A current flows in 6 ohm resistor from C to B

Example 2: pg 11

In [2]:
#pg 11
#calculate the current through all resistors
# Given data
V = 100.;# in V
I3= 10.;# in A
R1 = 10.;# in ohm 
R2 = 5.;# in ohm
# I1 = (V - V_A)/R1
# I2 = (V_A-0)/R2
# Using KCL at note A, I1-I2+I3=0 or
#calculations
V_A= (R1*R2)/(R1+R2)*(I3+V/R1);# in V
I1 = (V - V_A)/R1;# in A
I2 = (V_A-0)/R2;# in A
#results
print "The current through 10 ohm resistor in A is",round(I1,3)
print "The current through 5 ohm resistor in A is",round(I2,2)
print "The current through 20 ohm resistor in A is",I3
The current through 10 ohm resistor in A is 3.333
The current through 5 ohm resistor in A is 13.33
The current through 20 ohm resistor in A is 10.0

Example 3: pg 16

In [3]:
#pg 16
#calculate the equivalent current and voltage
# Given data
# Part (a)
V = 30.;# in V
R = 6;# in ohm
#calculations
I = V/R;# the equivalent current in A
print "The equivalent current in A is",I
# Part (b)
I = 10;# in A
R = 5;# in ohm
V = I*R;# the equivalent voltage in V
print "The equivalent voltage in V is",V
The equivalent current in A is 5.0
The equivalent voltage in V is 50

Example 4: pg 17

In [4]:
#pg 17
#calculate the current
# Given data
R1= 6.;# in ohm
R2= 2.;# in ohm
R3= 5.;# in ohm
I2= 4.;# in A
V=24.;#in V
# Applying KVL to the loop ABCDA, -R1*I1-R3*I+V=0  (i)
# but I1= I+I2 , so from eq(i)
#calculations
I= (V-R1*I2)/(R1+R3);# in A
#results
print "The current in A is",I
The current in A is 0.0

Example 5: pg 17

In [5]:
#pg 17
#calculate the value of current in different branches
# Given data
import numpy
R1= 40.;# in ohm
R2= 20.;# in ohm
R3= 25.;# in ohm
R4= 60.;# in ohm
R5= 50.;# in ohm
V1= 120.;# in V
V2= 60.;# in V
V3= 40.;# in V
#calculations
# Applying KVL in Mesh ABEFA, we get  -I1*(R1+R2+R3)+I2*R3=V2-V1       (i)
# Applying KVL in Mesh BCEDB, we get  R3*I1-I2*(R3+R4+R5)= V3-V2       (ii)
A= numpy.matrix([[-(R1+R2+R3), R3],[R3, -(R3+R4+R5)]]);
B= numpy.matrix([V2-V1, V3-V2]);
I= B*numpy.linalg.inv(A);#Solving eq(i) and (ii) by Matrix method
I1= I[0,0];# in A
I2= I[0,1];# in A
#results
print "The value of I1 in A is : ",round(I1,4)
print "The value of I2 in A is : ",round(I2,4)
The value of I1 in A is :  0.7926
The value of I2 in A is :  0.2949

Example 6: pg 18

In [6]:
#pg 18
#calculate the value of current in all branches
import numpy
# Given data
R1= 2.;# in ohm
R2= 4.;# in ohm
R3= 6.;# in ohm
V1= 4.;# in V
V2= 44.;# in V
#calculations
#Applying KVL in ABEFA :  -R1*I1 + R2*I2 = V1      (i)
#Applying KVL in BCDEB:  R3*I1 + I2*(R2+R3)=V2 (ii)
A= ([[-R1, R2],[R3, (R2+R3)]]); # assumed
B= ([[V1],[V2]]);# assumed
I=numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i) and (ii) by Matrix method
I1= I[0];# in A
I2= I[1];# in A
I_L= I1+I2;# in A
#results
print "The value of I1 in A is : ",round(I1,3)
print "The value of I2 in A is : ",round(I2,3)
print "The value of I_L in A is : ",round(I_L,3)
The value of I1 in A is :  3.091
The value of I2 in A is :  2.545
The value of I_L in A is :  5.636

Example 7: pg 19

In [7]:
#pg 19
#calculate the value of current
# Given data
import numpy
R1= 1;# in ohm
R2= 1;# in ohm
R3= 2;# in ohm
R4= 1;# in ohm
R5= 1;# in ohm
V1= 1.5;# in V
V2= 1.1;# in V
#calculations
#Applying KVL in ABCFA :  I1*(R1+R2+R3) + R3*I2 = V1      (i)
#Applying KVL in BCDEB:  R3*I1 + I2*(R3+R4+R5)=V2        (ii)
A= ([[(R1+R2+R3), R3],[R3, (R3+R4+R5)]]);
B= ([[V1], [V2]]);
I= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i) and (ii) by Matrix method
I1= I[0];# in A
I2= I[1];# in A
#results
print "The value of I1 in A is : ",round(I1,3)
print "The value of I2 in A is : ",round(I2,3)
The value of I1 in A is :  0.317
The value of I2 in A is :  0.117

Example 8: pg 20

In [9]:
#pg 20
#calculate the current
# Given data
import numpy
R1= 2.;# in ohm
R2= 4.;# in ohm
R3= 1.;# in ohm
R4= 6.;# in ohm
R5= 4.;# in ohm
V1= 10.;# in V
V2= 20.;# in V
#calculations
#Applying KVL in ABGHA :  I1*(R1+R2) - R2*I2 = V1                   (i)
#Applying KVL in BCFGB :  I1*R5-I2*(R3+R4+R5)+I3*R4 = 0      (ii)
#Applying KVL in CDEFC:  R4*I2-I3*(R2+R4)=V2                          (iii)
A= ([[(R1+R2), -R5, 0],[R2, -(R3+R4+R5), R4],[0, R4, -(R2+R4)]]);
B= ([[V1], [0], [V2]]);
I= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i), (ii) and (iii) by Matrix method
I1= I[0];# in A
I2= I[1];# in A
I3= I[2];# in A
I6_ohm_resistor= I2-I3;#The current through 6 ohm resistance  in A
#results
print "The current through 6 ohm resistance in A is : ",round(I6_ohm_resistor,4)
The current through 6 ohm resistance in A is :  1.5493

Example 9: pg 21

In [11]:
#pg 21
#calculate the current through resistances
# Given data
import numpy
R1= 30.;# in ohm
R2= 40.;# in ohm
R3= 20.;# in ohm
R4= 60.;# in ohm
R5= 50.;# in ohm
V= 240.;# in V
#calculations
#Applying KVL in ABDA  :  I1*-(R1+R2+R3) + R2*I2+R3*I3 =0                  (i)
#Applying KVL in BCDB  :  I1*R2+I2*-(R2+R4+R5)+I3*R5 = 0                   (ii)
#Applying KVL in CFEADC: I1*R3+ R5*I2+I3*-(R3+R5)=-V                       (iii)
A= ([[-(R1+R2+R3), R2, R3], [R2, -(R2+R4+R5), R5], [R3, R5, -(R3+R5)]]);
B= ([[0], [0], [-V]]);
I= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i), (ii) and (iii) by Matrix method
I1= I[0];# in A
I2= I[1];# in A
I3= I[2];# in A
I30_ohm_resistor= I1;# in A
I60_ohm_resistor= I2;# in A
I50_ohm_resistor= I2-I3;# in A
I20_ohm_resistor= I1-I3;# in A
I40_ohm_resistor= I1-I2;# in A
#results
print "The current through 30 ohm resistance in A is : ",round(I30_ohm_resistor,2)
print "The current through 60 ohm resistance in A is : ",round(I60_ohm_resistor,2)
print "The current through 50 ohm resistance in A is : ",round(I50_ohm_resistor,2)
print "The current through 20 ohm resistance in A is : ",round(I20_ohm_resistor,2)
print "The current through 40 ohm resistance in A is : ",round(I40_ohm_resistor,2)

print'Note: In the book there is a mistake in eq(iii), the R.H.S of eq(iii) should be -24 not -240. Since they divide the L.H.S of eq(iii) by 10 and R.H.S not divided, So the answer in the book is wrong'  
The current through 30 ohm resistance in A is :  2.56
The current through 60 ohm resistance in A is :  2.72
The current through 50 ohm resistance in A is :  -3.38
The current through 20 ohm resistance in A is :  -3.54
The current through 40 ohm resistance in A is :  -0.15
Note: In the book there is a mistake in eq(iii), the R.H.S of eq(iii) should be -24 not -240. Since they divide the L.H.S of eq(iii) by 10 and R.H.S not divided, So the answer in the book is wrong

Example 10: pg 22

In [12]:
#pg 22
#calculate the current
# Given data
import numpy
R1= 5.;# in ohm
R2= 5.;# in ohm
R3= 10.;# in ohm
R4= 10.;# in ohm
R5= 5.;# in ohm
V1= 50.;# in V
V2= 20.;# in V
#calculations
#Applying KCL at node A:  VA*(R1*R3+R3*R2+R2*R1)+VB*-R1*R3 = V1*R2*R3                 (i)
#Applying KCL at node B:  VA*R4*R5+VB*-(R2*R4+R4*R5+R5*R2) = -V2*R2*R4              (ii)

A=([[(R1*R3+R2*R3+R2*R1), -R4*R5], [-R1*R3, (R2*R4+R4*R5+R5*R2)]])
B= ([[V1*R2*R3], [V2*R2*R4]]);
V= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i) and (ii) by Matrix method
VA= V[0];# in V
VB= V[1];# in V
I_through_R3= VA/R3;# in A
I_through_R4= VB/R4;# in A
#results
print "The current in R3 in A is : ",round(I_through_R3,4)
print "The current in R4 in A is : ",round(I_through_R4,4)
The current in R3 in A is :  2.7619
The current in R4 in A is :  1.9048

Example 11: pg 23

In [13]:
#pg 23
#calculate the current
# Given data
import numpy
R1= 1.;# in ohm
R2= 1.;# in ohm
R3= 0.5;# in ohm
R4= 2.;# in ohm
R5= 1.;# in ohm
V1= 15.;# in V
V2= 20.;# in V
#calculations
#Applying KCL at node A:  VA*(R1*R2+R2*R3+R3*R1)+VB*-R1*R2 = V1*R2*R3                 (i)
#Applying KCL at node B:  VA*R4*R5+VB*-(R3*R4+R4*R5+R5*R3) = V2*R3*R4                (ii)
A=([[2*(R1*R2+R2*R3+R3*R1), -R4*R5], [2*R1*R2, -(R3*R4+R4*R5+R5*R3)]])
B= ([[2*V1*R2*R3], [-V2*R3*R4]]);
V= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i) and (ii) by Matrix method
VA= V[0];# in V
VB= V[1];# in V
I1= (VA-V1)/R1;# in A
I2= VA/R2;# in A
I3= (VA-VB)/R3;# in A
I4= VB/R4;# in A
I5= (VB-V2)/R5;# in A
#results
print "The value of I1 in A is : ",I1
print "The value of I2 in A is : ",I2
print "The value of I3 in A is : ",I3
print "The value of I4 in A is : ",I4
print "The value of I5 in A is : ",I5
The value of I1 in A is :  [-5.75]
The value of I2 in A is :  [ 9.25]
The value of I3 in A is :  [-3.5]
The value of I4 in A is :  [ 5.5]
The value of I5 in A is :  [-9.]

Example 12: pg 24

In [14]:
#pg 24
#calculate the value of current
# Given data
V1 = 12.;# in V
V2 = 10.;# in V
VB = 0.;# in V
R1 = 2.;# in ohm
R2 = 1.;# in ohm
R3 = 10.;# in ohm
#calculations
# Using KCL at node A :
VA= (V1*R2*R3+V2*R3*R1)/(R1*R2+R2*R3+R3*R1);# in V
I1 = (V1-VA)/R1;# in A
I2 = (V2-VA)/R2;# in A
I3 = (VA-VB)/R3;# in A
#results
print "The value of I1 in A is : ",I1
print "The value of I2 in A is : ",I2
print "The value of I3 in A is : ",I3
The value of I1 in A is :  1.0
The value of I2 in A is :  0.0
The value of I3 in A is :  1.0

Example 13: pg 25

In [15]:
#pg 25
#calculate the voltage at all nodes
# Given data
import numpy
R1= 1.;# in ohm
R2= 2.;# in ohm
R3= 2.;# in ohm
R4= 1.;# in ohm
I1= 1.;# in A
I5= 2.;# in A
#calculations
# Using KCL at node 1: V1*(R2+R3)-V2*R2= I1*R2*R3        (i)
# Using KCL at node 2: V1*R4-V2*(R3+R4)= -I5*(R3*R4)   (ii)
A= ([[(R2+R3), -R4], [R2, -(R3+R4)]]);
B= ([[I1*R2*R3], [-2*I5*R3*R4]]);
V= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i) and (ii) by Matrix method
V1= V[0];# in V
V2= V[1];# in V
#results
print"The voltage at node 1 in volts is : ",V1
print "The voltage at node 2 in volts is : ",V2
The voltage at node 1 in volts is :  [ 2.]
The voltage at node 2 in volts is :  [ 4.]

Example 14: pg 26

In [16]:
#pg 26
# Given data
#calculate the value of current
import numpy
R1= 2.;# in ohm
R2= 6.;# in ohm
R3= 3.;# in ohm
V1= 10.;# in V
V2= 6.;# in V
V3= 2.;# in V
#calculations
#Applying KVL in ABEFA  :  I1*(R1+R2) - R2*I2=V1-V2                  (i)
#Applying KVL in BCDEB  :  -I1*R2+I2*(R2+R3)=V2-V3                   (ii)
A= ([[(R1+R2), -R2], [-R2, (R2+R3)]]);
B= ([[(V1-V2)], [(V2-V3)]]);
I= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i),  and (ii) by Matrix method
I1= I[0];# in A
I2= I[1];# in A
#results
print "The value of I1 in A is : ",round(I1,3)
print "The value of I2 in A is : ",round(I2,2)
The value of I1 in A is :  1.667
The value of I2 in A is :  1.56

Example 15: pg 26

In [17]:
#pg 26
#calculate the value of current
# Given data
import numpy
R1= 2.;# in ohm
R2= 6.;# in ohm
R3= 4.;# in ohm
R4= 3.;# in ohm
R5= 5.;# in ohm
V1= 10.;# in V
V2= 6.;# in V
V3= 2.;# in V
#calculations
#Applying KVL in ABEFA :  I1*(R1+R2+R3) - R2*I2 = V1-V2  (i)
#Applying KVL in BCDEB :  I1*-R2+I2*(R2+R4+R5) =V2-V3  (ii)
A= ([[(R1+R2+R3), -R2], [-R2, (R2+R4+R5)]]);
B= ([[(V1-V2)], [(V2-V3)]]);
I= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i) and (ii) by Matrix method
I1= I[0];# in A
I2= I[1];# in A
#results
print "The value of I1 in A is : ",round(I1,3)
print "The value of I2 in A is : ",round(I2,3)
The value of I1 in A is :  0.606
The value of I2 in A is :  0.545

Example 16: pg 27

In [18]:
#pg 27
#calculate the current
# Given data
import numpy
R1= 10.;# in ohm
R2= 5.;# in ohm
R3= 5.;# in ohm
R4= 5.;# in ohm
V2= 10.;# in V
I= 1.;# in A
#calculations
V1= R4*I;# in V
#Applying KVL in ABEFA :  I1*(R1+R2+R3) + R1*I2 = V1  (i)
#Applying KVL in BCDEB :  I1*R1+I2*(R1+R4) =V2            (ii)
A= ([[(R1+R2+R3), R1], [R1, (R1+R4)]]);
B= ([[V1], [V2]]);
I= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i) and (ii) by Matrix method
I1= I[0];# in A
I2= I[1];# in A
I10_ohm= I1+I2;# in A
#results
print "The current through 10 ohm resistor in A is : ",I10_ohm
The current through 10 ohm resistor in A is :  [ 0.625]

Example 17: pg 28

In [19]:
#pg 28
#calculate the current
# Given data
import numpy
R1= 4.;# in ohm
R2= 5.;# in ohm
R3= 10.;# in ohm
R4= 6.;# in ohm
R5= 4.;# in ohm
V1= 15.;# in V
V2= 30.;# in V
#calculations
#Applying KCL at node A:  VA*(R1*R2+R2*R3+R3*R1)+VB*-R1*R2 = V1*R1*R3                 (i)
#Applying KCL at node B:  VA*R4*R5+VB*-(R3*R4+R4*R5+R5*R3) = -V2*R3*R4                (ii)
A=([[(R1*R2+R2*R3+R3*R1), -R4*R5], [R1*R2, -(R3*R4+R4*R5+R5*R3)]])
B= ([[V1*R1*R3], [-V2*R3*R4]]);
V= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i) and (ii) by Matrix method
VA= V[0];# in V
VB= V[1];# in V
I10_ohm= abs((VA-VB)/R3);# in A
#results
print "The current through 10 ohm resistor from right to left in A is : ",round(I10_ohm,3)
The current through 10 ohm resistor from right to left in A is :  0.702

Example 19: pg 29

In [20]:
#pg 29
#calculate the current
# Given data
import numpy
R1= 10.;# in ohm
R2= 10.;# in ohm
R3= 20.;# in ohm
R4= 20.;# in ohm
R5= 20.;# in ohm
V= 10.;# in V
I1= 1.;# in A
I7=0.5;# in A
#calculations
#Applying KCL at node A:  VA*(R1+R2)+VB*-R1 = I1*R1*R2                                                                 (i)
#Applying KCL at node B:  VA*R3*R4+VB*-(R2*R3+R3*R4+R4*R2)+VC*R2*R3 = V*R2*R4      (ii)
#Applying KCL at node C: -VB*R5+VC*(R4+R5)=I7*R4*R5                                                                   (iii)
A=([[(R1+R2), -R1, 0], [R3*R4, -(R2*R3+R3*R4+R4*R2), R2*R3],[0, -R5, (R4+R5)]])
B= ([[I1*R1*R2], [V*R2*R4], [I7*R4*R5]]);
Value= numpy.dot(numpy.linalg.inv(A),B);# Solving eq(i), (ii) and (iii) by Matrix method
VA= Value[0];# in V
VB= Value[1];# in V
VC= Value[2]
I2= VA/R1;# in A
I3= (VA-VB)/R2;# in A
I4= (VB+V)/R3;# in A
I5= (VC-VB)/R4;# in A
I6= VC/R5;# in A
#results
print "The value of I1 in A is : ",I1
print "The value of I2 in A is : ",I2
print "The value of I3 in A is : ",I3
print "The value of I4 in A is : ",I4
print "The value of I5 in A is : ",I5
print "The value of I6 in A is : ",I6
print "The value of I7 in A is : ",I7
The value of I1 in A is :  1.0
The value of I2 in A is :  [ 0.6]
The value of I3 in A is :  [ 0.4]
The value of I4 in A is :  [ 0.6]
The value of I5 in A is :  [ 0.2]
The value of I6 in A is :  [ 0.3]
The value of I7 in A is :  0.5

Example 20: pg 31

In [21]:
#pg 31
#calculate the current
# Given data
import numpy
R1 = 3.;# in ohm
R2 = 8.;# in ohm
R3 = 4.;# in ohm
R4 = 12.;# in ohm
R5 = 14.;# in ohm
V1 = 10.;# in V
V2 = 3.;# in V
V3 = 6.;# in V
#Applying KCL at node A:  VA*(R1*R2+R2*R3+R3*R1)+VB*-R1*R2 = V1*R2*R3+V2*R1*R2                 (i)
#Applying KCL at node B:  VA*R4*R5+VB*-(R3*R4+R4*R5+R5*R3) = V2*R4*R5-V3*R3*R4                (ii)
A=([[(R1*R2+R2*R3+R3*R1), R4*R5], [-R1*R2, -(R3*R4+R4*R5+R5*R3)]])
B= ([(V1*R2*R3+V2*R1*R2), (V2*R4*R5-V3*R3*R4)])
V= numpy.dot(B,numpy.linalg.inv(A));# Solving eq(i) and (ii) by Matrix method
VA= V[0];# in V
VB= V[1];# in V
I8_ohm= VA/R2;#The current through 8 ohm resistance  in A
#results
print "The current through 8 ohm resistance in A is : ",round(I8_ohm,4)
The current through 8 ohm resistance in A is :  0.8767

Example 21: pg 32

In [22]:
#pg 32
#calculate the current
# Given data
V= 100.;# in V
R12 = 3.;# in ohm
R31 = 2.;# in ohm
R23 = 4.;# in ohm
R4= 6.;# in ohm
R5=2.;# in ohm
R6= 5.;# in ohm
#calculations
R1 = (R12*R31)/(R12+R23+R31);# in ohm
R2 = (R31*R23)/(R12+R23+R31);# in ohm
R3 = (R23*R12)/(R12+R23+R31);# in ohm
R_S= R6+R1;# in ohm
R_P1= R2+R4;# in ohm
R_P2= R3+R5;# in ohm
R_P= R_P1*R_P2/(R_P1+R_P2);# in ohm
R= R_P+R_S;# in ohm
I= V/R;# in A
#results
print "The current drawn from the source in A is : ",round(I,2)
The current drawn from the source in A is :  12.64

Example 22: pg 33

In [23]:
#pg 33
#calculate the current using both methods
# Given data
R1= 10.;# in ohm
R2= 5.;# in ohm
R3= 20.;# in ohm
V= 100.;# in V
I2= 10.;# in A
#calculations
# Applying KVL in ABEFA : -R1*I1-R2*(I1+I2)+V= 0
I1= (V-R2*I2)/(R1+R2);# in A
I10_ohm= I1;#current through 10 ohm resistance in A
I5_ohm= I1+I2;#current through 5 ohm resistance in A
I20_ohm= I2;#current through 20 ohm resistance in A
print "Part (i) : Using by KVL"
print "The current through 10 ohm resistance in A is : ",round(I10_ohm,2)
print "The current through 5 ohm resistance in A is : ",round(I5_ohm,2)
print "The current through 20 ohm resistance in A is : ",I20_ohm
# Applying KCL at node A :
VA= (V*R2+I2*R1*R2)/(R1+R2);# in V
I10_ohm= (VA-V)/R1;# in A
I5_ohm= VA/R2;# in A
I20_ohm= I2;# in A
print "Part (ii) : Using by KVL"
print "The current through 10 ohm resistance in A is : ",round(I10_ohm,2)
print "The current through 5 ohm resistance in A is : ",round(I5_ohm,2)
print "The current through 20 ohm resistance in A is : ",I20_ohm
Part (i) : Using by KVL
The current through 10 ohm resistance in A is :  3.33
The current through 5 ohm resistance in A is :  13.33
The current through 20 ohm resistance in A is :  10.0
Part (ii) : Using by KVL
The current through 10 ohm resistance in A is :  -3.33
The current through 5 ohm resistance in A is :  13.33
The current through 20 ohm resistance in A is :  10.0

Example 23: pg 34

In [24]:
#pg 34
#calculate the current and voltage
# Given data
import numpy
R1= 5.;# in ohm
R2= 10.;# in ohm
R3= 3.;# in ohm
R4= 2.;# in ohm
V1= 10.;# in V
V2= 20.;# in V
I= 5.;# in A
#Applying KCL at node A:  VA*(R1+R2)+VB*-R1 =I*R1*R2+V1*R1                                                 (i)
#Applying KCL at node B:  VA*R3*R4+VB*-(R2*R3+R4*R3+R4*R2) =V1*R3*R4+V2*R2*R3 (ii)
A=([[(R1+R2), R3*R4], [-R1, -(R3*R2+R4*R3+R4*R2)]])
B= ([(I*R1*R2+V1*R1), (V1*R3*R4+V2*R2*R3)]);
V= numpy.dot(B,numpy.linalg.inv(A));# Solving eq(i) and (ii) by Matrix method
VA= V[0];# in V
VB= V[1];# in V
I4= (VB+V2)/R4;# in A
V4= R4*I4;# in V
#results
print "The current through 2 ohm resistor in A is : ",I4
print "The voltage across 2 ohm resistor in V is : ",V4
The current through 2 ohm resistor in A is :  5.0
The voltage across 2 ohm resistor in V is :  10.0

Example 24: pg 36

In [25]:
#pg 36
#calculate the voltage
# Given data
import numpy
R1= 6.;# in ohm
R2= 12.;# in ohm
R3= 2.;# in ohm
R4= 6.;# in ohm
V2= 12.;# in V
V3= 30.;# in V
#calculations
#Applying KVL in ABEFA  :  I1*(R1+R2) - R2*I2=V3-V2                  (i)
#Applying KVL in BCDEB  :  -I1*R2+I2*(R1+R2+R3)=V2                   (ii)
A= ([[(R1+R2), -R2], [-R2, (R1+R2+R3)]]);
B= ([(V3-V2), (V2)]);
I= numpy.dot(B,numpy.linalg.inv(A));# Solving eq(i),  and (ii) by Matrix method
I1= I[0];# in A
I2= I[1];# in A
V1= I2*R1;#voltage across 6 ohm resistor  in V
#results
print "The voltage across 6 ohm resistor in V is : ",V1
The voltage across 6 ohm resistor in V is :  12.0

Example 25: pg 36

In [26]:
#pg 36
#calculate the resistance
# Given data
R1 = 6.;# in ohm
R2 = 2.;# in ohm
R3 = 2.;# in ohm
R4 = 4.;# in ohm
R5 = 4.;# in ohm
R6 = 6.;# in ohm
#calculations
R12= R1*R2/(R1+R2);# in ohm
R34= R3*R4/(R3+R4);# in ohm
R56= R5*R6/(R5+R6);# in ohm
# Resistance between the point B and C
R_BC= (R12+R34)*R56/((R12+R34)+R56);# in ohm
#results
print "The resistance between the point B and C in ohm is : ",round(R_BC,1)
The resistance between the point B and C in ohm is :  1.3

Example 26: pg 37

In [27]:
#pg 37
#calculate the voltage across resistors
# Given data
R1 = 10.;# in ohm
R2 = 10.;# in ohm
R4 = 80.;# in ohm
V1= 100.;# in V
I2= 0.5;# in A
#calculations
V2= I2*R4;# in V
# Applying KVL : -R1*I1-V2+V1-R1*I2=0
I1= (V1-V2)/(R1+R2);# in A
V_R1= I1*R1;#voltage across R1 resistor  in V
V_R2= I1*R2;#voltage across R2 resistor  in V
#results
print "The voltage across R1 resistor in V is : ",V_R1
print "The voltage across R2 resistor in V is : ",V_R2
The voltage across R1 resistor in V is :  30.0
The voltage across R2 resistor in V is :  30.0

Example 27: pg 38

In [28]:
#pg 38
#calculate the currents
# Given data
import numpy
R1 = 8.;# in ohm
R2 = 4.;# in ohm
R3 = 4.;# in ohm
R4 = 4.;# in ohm
R5 = 8.;# in ohm
R6 = 8.;# in ohm
I=10.;# in A
V= 20.;# in V
#calculations
# Applying KVL in ABEFA : I1*(R1+R2+R3)+I2*(R3)= I*R2-V    (i)
# Applying KVL in BCDEB : I1*R3-I2*(R3+R4+R5)= R4*I+V      (ii)
A= ([[(R1+R2+R3), R3], [R3, -(R3+R4+R5)]]);
B= ([I*R2-V, R4*I+V]);
I= numpy.dot(B,numpy.linalg.inv(A));## Solving equations by matrix multiplication
I1= I[0];# in A
I2= I[1];# in A
#results
print "The value of I1 in A is : ",round(I1,2)
print "The value of I2 in A is : ",round(I2,2)
The value of I1 in A is :  2.06
The value of I2 in A is :  -3.24