from __future__ import division
import math
import cmath
#initializing the variables:
rv1 = 100;# in volts
rv2 = 50;# in volts
thetav1 = 0;# in degrees
thetav2 = 90;# in degrees
R1 = 25;# in ohm
R2 = 20;# in ohm
R3 = 10;# in ohm
#calculation:
#voltage
V1 = rv1*math.cos(thetav1*math.pi/180) + 1j*rv1*math.sin(thetav1*math.pi/180)
V2 = rv2*math.cos(thetav2*math.pi/180) + 1j*rv2*math.sin(thetav2*math.pi/180)
#The branch currents and their directions are labelled as shown in Figure 30.4
#Two loops are chosen. loop ABEF, and loop BCDE
#using kirchoff rule in 3 loops
#two eqns obtained
#(R1 + R2)*I1 + R2*I2 = V1
#R2*I1 + (R2 + R3)*I2 = V2
I1 = (3*V1 - 2*V2)/(3*(R1 + R2) - 2*(R2))
I2 = (V2 - R2*I1)/(R2 + R3)
I = I1 + I2
#Results
print "\n\n Result \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 and "
print " total current, I is ",round(I.real,2)," + (",round( I.imag,2),")i A"
from __future__ import division
import math
import numpy
#initializing the variables:
V = 8;# in volts
R1 = 1;# in ohm
R2 = 2;# in ohm
R3 = 3;# in ohm
R4 = 4;# in ohm
R5 = 5;# in ohm
R6 = 6;# in ohm
#calculation:
#Currents and their directions are assigned as shown in Figure 30.6.
#Three loops are chosen since three unknown currents are required. The choice of loop directions is arbitrary.
#loop ABCDE, and loop EDGF and loop DCHG
#using kirchoff rule in 3 loops
#three eqns obtained
#R5*I1 + (R6 + R4)*I2 - R4*I3 = V
#-1*R1*I1 + (R6 + R1)*I2 + R2*I3 = 0
# R3*I1 - (R3 + R4)*I2 + (R2 + R3 + R4)*I3 = 0
#using determinants
d1 = [[V, (R6 + R4), -1*R4],[0, (R6 + R1), R2], [0, (-1*(R3 + R4)), (R2 + R3 + R4)]]
D1 = numpy.linalg.det(d1)
d2 = [[R5, V, -1*R4],[-1*R1, 0, R2],[ R3, 0, (R2 + R3 + R4)]]
D2 = numpy.linalg.det(d2)
d3 = [[R5, (R6 + R4), V],[-1*R1, (R6 + R1), 0],[ R3, (-1*(R3 + R4)), 0]]
D3 = numpy.linalg.det(d3)
d = [[R5, (R6 + R4), -1*R4],[-1*R1, (R6 + R1), R2],[ R3, (-1*(R3 + R4)), (R2 + R3 + R4)]]
D = numpy.linalg.det(d)
I1 = D1/D
I2 = D2/D
I3 = D3/D
#Current in the 2 ohm resistance
I = I1 - I2 + I3
#power dissipated in the 3 ohm resistance
P3 = R3*I**2
#Results
print "\n\n Result \n\n"
print "\n (a)current through 2 ohm resistor is ",round(I2,3)," A"
print "\n (b)power dissipated in the 3 ohm resistor is ",round(P3,3),"W"
from __future__ import division
import math
import cmath
#initializing the variables:
E1 = 5 + 0j;# in volts
E2 = 2 + 4j;# in volts
Z1 = 3 + 4j;# in ohm
Z2 = 2 - 5j;# in ohm
Z3 = 6 + 8j;# in ohm
#calculation:
#Currents I1 and I2 with their directions are shown in Figure 30.8.
#Two loops are chosen with their directions both clockwise.loop ABEF and loop BCDE,
#using kirchoff rule in 3 loops
#two eqns obtained
#(Z1 + Z3)*I1 - Z3*I2 = E1
#-1*Z3*I1 + (Z2 + Z3)*I2 = E2
I1 = ((Z2 + Z3)*E1 + Z3*E2)/((Z2 + Z3)*(Z1 + Z3) - Z3*Z3)
I2 = -1*(E1 - (Z1 + Z3)*I1)/Z3
I3 = I1 - I2
#Results
print "\n\n Result \n\n"
print "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 and "
print " current, I3 is ",round(I3.real,2)," + (",round( I3.imag,2),")i A"
from __future__ import division
import math
import numpy
import cmath
#initializing the variables:
rv1 = 10;# in volts
rv2 = 12;# in volts
rv3 = 15;# in volts
thetav1 = 0;# in degrees
thetav2 = 0;# in degrees
thetav3 = 0;# in degrees
R1 = 4;# in ohm
R2 = -5j;# in ohm
R3 = 8;# in ohm
R4 = 4;# in ohm
R5 = 3j;# in ohm
#calculation:
#voltages
V1 = rv1*math.cos(thetav1*math.pi/180) + 1j*rv1*math.sin(thetav1*math.pi/180)
V2 = rv2*math.cos(thetav2*math.pi/180) + 1j*rv2*math.sin(thetav2*math.pi/180)
V3 = rv3*math.cos(thetav3*math.pi/180) + 1j*rv3*math.sin(thetav3*math.pi/180)
#Currents I1, I2 and I3 with their directions are shown in Figure 30.10.
#Three loops are chosen. The choice of loop directions is arbitrary. loop ABGH, and loopBCFG and loop CDEF
Z4 = R4 + R5
#using kirchoff rule in 3 loops
#three eqns obtained
#R1*I1 + R2*I2 = V1 + V2
#-1*R3*I1 + (R3 + R2)*I2 + R3*I3 = V2 + V3
# -1*R3*I1 + R3*I2 + (R3 + Z4)*I3 = V3
#using determinants
d1 = [[(V1 + V2), R2, 0],[(V2 + V3), (R3 + R2), R3],[V3, R3, (R3 + Z4)]]
D1 = numpy.linalg.det(d1)
d2 = [[R1, (V1 + V2), 0],[-1*R3, (V2 + V3), R3],[-1*R3, V3, (R3 + Z4)]]
D2 = numpy.linalg.det(d2)
d3 = [[R1, R2, (V1 + V2)],[-1*R3, (R3 + R2), (V2 + V3)],[-1*R3, R3, V3]]
D3 = numpy.linalg.det(d3)
d = [[R1, R2, 0],[-1*R3, (R3 + R2), R3],[-1*R3, R3, (R3 + Z4)]]
D = numpy.linalg.det(d)
I1 = D1/D
I2 = D2/D
I3 = D3/D
I3mag = abs(I3)
#Results
print "\n\n Result \n\n"
print "\n magnitude of the current through (4 + i3)ohm impedance is ",round(I3mag,2)," A"