from __future__ import division
import math
import numpy
import cmath
#initializing the variables:
V1 = 4;# in volts
V2 = 5;# in volts
R1 = 3;# in ohm
R2 = 5;# in ohm
R3 = 4;# in ohm
R4 = 1;# in ohm
R5 = 6;# in ohm
R6 = 8;# in ohm
#calculation:
#The mesh currents I1, I2 and I3 are shown in Figure 31.2. Using Kirchhoff’s voltage law in 3 loops
#three eqns obtained
#(R1 + R2)*I1 - R2*I2 = V1
#-1*R2*I1 + (R2 + R3 + R4 + R5)*I2 - R4*I3 = 0
# -1*R4*I2 + (R4 + R6)*I3 = -1*V2
#using determinants
d1 = [[V1, -1*R2, 0],[0, (R2 + R3 + R4 + R5), -1*R4],[-1*V2, -1*R4, (R4 + R6)]]
D1 = numpy.linalg.det(d1)
d2 = [[(R1 + R2), V1, 0],[-1*R2, 0, -1*R4],[0, -1*V2, (R4 + R6)]]
D2 = numpy.linalg.det(d2)
d3 = [[(R1 + R2), -1*R2, V1],[-1*R2, (R2 + R3 + R4 + R5), 0],[0, -1*R4, -1*V2]]
D3 = numpy.linalg.det(d3)
d = [[(R1 + R2), -1*R2, 0],[-1*R2, (R2 + R3 + R4 + R5), -1*R4],[0, -1*R4, (R4 + R6)]]
D = numpy.linalg.det(d)
I1 = D1/D
I2 = D2/D
I3 = D3/D
IR2 = I1 - I2
IR4 = I2 - I3
#Results
print "\n\n Result \n\n"
print "\n (a)current in the 5 ohm resistance is ",round(IR2,2)," A"
print "\n (b)current in the 1 ohm resistance is ",round(IR4,2)," A"
from __future__ import division
import math
import numpy
import cmath
#initializing the variables:
rv = 100;# in volts
thetav = 0;# in degrees
R1 = 5;# in ohm
R2 = -1j*4;# in ohm
R3 = 4;# in ohm
R4 = 3j;# in ohm
#calculation:
#voltages
V = rv*math.cos(thetav*math.pi/180) + 1j*rv*math.sin(thetav*math.pi/180)
#Currents I1, I2 with their directions are shown in Figure 31.03.
#Two loops are chosen. The choice of loop directions is arbitrary.
#using kirchoff rule in 2 loops
#two eqns obtained
#(R1 + R2)*I1 - R2*I2 = V
#-1*R2*I1 + (R3 + R2 + R4)*I2 = 0
#using determinants
d1 = [[V, -1*R2],[0, (R3 + R2 + R4)]]
D1 = numpy.linalg.det(d1)
d2 = [[(R1 + R2), V],[-1*R2, 0]]
D2 = numpy.linalg.det(d2)
d = [[(R1 + R2), -1*R2],[-1*R2, (R3 + R2 + R4)]]
D = numpy.linalg.det(d)
I1 = D1/D
I2 = D2/D
I1mag = abs(I1)
#Current flowing in capacitor
Ic = I1 - I2
#Source power P
phi = cmath.phase(complex(I1.real,I1.imag))
P = V*I1mag*math.cos(phi)
Icmag = abs(Ic)
#Results
print "\n\n Result \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"
print "(b)current in the capacitor is ",round(Icmag,2)," A"
print "(c)Source power P is ",round(abs(P),2)," W"
from __future__ import division
import math
import numpy
import cmath
#initializing the variables:
rv1 = 415;# in volts
rv2 = 415;# in volts
thetav1 = 120;# in degrees
thetav2 = 0;# in degrees
R = 3 + 4j;# 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)
#Two mesh currents I1 and I2 are chosen as shown in Figure 31.4.
#Two loops are chosen. The choice of loop directions is arbitrary.
#using kirchoff rule in 2 loops
#two eqns obtained
#2*R*I1 - R*I2 = V1
#-1*R*I1 + 2*R*I2 = V2
#using determinants
d1 = [[V1, -1*R],[V2, 2*R]]
D1 = numpy.linalg.det(d1)
d2 = [[2*R, V1],[-1*R, V2]]
D2 = numpy.linalg.det(d2)
d = [[2*R, -1*R],[-1*R, 2*R]]
D = numpy.linalg.det(d)
I1 = D1/D
I2 = D2/D
I1mag = abs(I1)
#line current IR
IR = I1
#line current IB
IB = -1*I2
#line current IY
IY = I2 - I1
#Results
print "\n\n Result \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"
from __future__ import division
import math
import cmath
#initializing the variables:
ri = 20;# in amperes
thetai = 0;# in degrees
R1 = 10;# in ohm
R2 = 3j;# in ohm
R3 = 4;# in ohm
R4 = 16;# in ohm
#calculation:
#current
I = ri*math.cos(thetai*math.pi/180) + 1j*ri*math.sin(thetai*math.pi/180)
#Figure 31.8 contains two principal nodes (at 1 and B) and thus only one nodal equation is required.
#B is taken as the reference node and the equation for node 1 is obtained as follows.
#Applying Kirchhoff’s current law to node 1 gives:
#IX + IY = I
V1 = I/((1/R4) +(1/(R2 +R3)))
IY = V1/(R2 + R3)
VAB = IY*R3
#Results
print "\n\n Result \n\n"
print "\n voltage VAB is ",round(VAB.real,2)," + (",round( VAB.imag,2),")i V"
from __future__ import division
import math
import cmath
#initializing the variables:
rv1 = 8;# in volts
rv2 = 8;# in volts
thetav1 = 0;# in degrees
thetav2 = 90;# in degrees
R1 = 5;# in ohm
R2 = 6j;# in ohm
R3 = 4;# in ohm
R4 = 3;# 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)
#The circuit contains no principal nodes.
#However, if point Y is chosen as the reference node then an equation
#may be written for node X assuming that current leaves point X by both branches
VX = ((V1/(R1 + R3) + V2/(R2 + R4))/(1/(R1 + R3) + 1/(R2 + R4)))
VXY = VX
#Results
print "\n\n Result \n\n"
print "\n voltage VXY = ",round(abs(VXY),2),"/_",round(cmath.phase(complex(VXY.real, VXY.imag))*180/math.pi,2),"deg V"
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:
#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)
#There are only two principal nodes in Figure 31.10 so only one nodal equation is required.
#Node 2 is taken as the reference node.
#The equation at node 1 is I1 + I2 + I3 = 0
Vn1 = ((V1/R1 + V2/R3)/(1/R1 + 1/R2 + 1/R3))
I1 = (Vn1 - V1)/R1
I2 = Vn1/R2
I3 = (Vn1 - V2)/R3
#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 \n and 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 = 25;# in volts
rv2 = 25;# in volts
thetav1 = 0;# in degrees
thetav2 = 90;# in degrees
R1 = 2;# in ohm
R2 = -1j*4;# in ohm
R3 = 5;# in ohm
R4 = 4j;# in ohm
R5 = 2.5;# 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)
#The equation at node 1
#Vn1*(1/R1 + 1/R2 + 1/R3) - Vn2/R3 = V1/R1
#The equation at node 2
#Vn1*(-1/R3) + Vn2*(1/R4 + 1/R5 + 1/R3) = V2/R5
#using determinants
d1 = [[V1/R1, -1/R3],[V2/R5, (1/R4 + 1/R5 + 1/R3)]]
D1 = numpy.linalg.det(d1)
d2 = [[(1/R1 + 1/R2 + 1/R3), V1/R1],[-1/R3, V2/R5]]
D2 = numpy.linalg.det(d2)
d = [[(1/R1 + 1/R2 + 1/R3), -1/R3],[-1/R3, (1/R4 + 1/R5 + 1/R3)]]
D = numpy.linalg.det(d)
Vn1 = D1/D
Vn2 = D2/D
#current in the j4 ohm inductance is given by:
I4 = Vn2/R4
#current in the 5 ohm resistance is given by:
I3 = (Vn1 - Vn2)/R3
#active power dissipated in the 2.5 ohm resistor is given by
P5 = R5*((Vn2 - V2)/R5)**2
#magnitude of the active power dissipated
P5mag = abs(P5)
#Results
print "\n\n Result \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"
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"
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"
print "\n (d) magnitude of the active power dissipated in the 2.5 ohm resistance is ",round(P5mag,2)," W"
from __future__ import division
import math
import numpy
import cmath
#initializing the variables:
ri = 25;# in amperes
thetai = 0;# in degrees
R1 = 4;# in ohm
R2 = 3j;# in ohm
R3 = 5;# in ohm
R4 = 10j;# in ohm
R5 = 20j;# in ohm
#calculation:
#current
I = ri*math.cos(thetai*math.pi/180) + 1j*ri*math.sin(thetai*math.pi/180)
#Node 3 is taken as the reference node.
#At node 1,
#V1*(1/(R1 + R2) + 1/R3) - V2/R3 = I
#The equation at node 2
#V1*(-1/R3) + V2*(1/R4 + 1/R5 + 1/R3) = 0
#using determinants
d1 = [[I, -1/R3],[0 , (1/R4 + 1/R5 + 1/R3)]]
D1 = numpy.linalg.det(d1)
d2 = [[(1/(R1 + R2) + 1/R3), I],[-1/R3, 0]]
D2 = numpy.linalg.det(d2)
d = [[(1/(R1 + R2) + 1/R3), -1/R3],[-1/R3, (1/R4 + 1/R5 + 1/R3)]]
D = numpy.linalg.det(d)
V1 = D1/D
V2 = D2/D
#the voltage between point X and node 3 is
VX = V1*R2/(R1 + R2)
#Thus the voltage
VY = V2
VXY = VX - VY
#Results
print "\n\n Result \n\n"
print "\n voltage VXY is ",round(VXY.real,2)," + (",round( VXY.imag,2),")i V"
from __future__ import division
import math
import numpy
import cmath
#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:
#In Figure 31.13, the reference node is shown at point A.
#At node 1,
#V1*(1/R1 + 1/R6 + 1/R5) - V2/R1 - V3/R5 = V/R5
#The equation at node 2
#V1*(-1/R1) + V2*(1/R2 + 1/R1 + 1/R3) - V3/R3 = 0
#At node 3
# - V1/R5 - V2/R3 + V3*(1/R4 + 1/R3 + 1/R5) = -1*V/R5
#using determinants
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)]]
D1 = numpy.linalg.det(d1)
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)]]
D2 = numpy.linalg.det(d2)
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]]
D3 = numpy.linalg.det(d3)
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)]]
D = numpy.linalg.det(d)
Vn1 = D1/D
Vn2 = D2/D
Vn3 = D3/D
#the current in the 2 ohm resistor
I2 = Vn2/R2
#power dissipated in the 3 ohm resistance
P3 = R3*((Vn2 - Vn3)/R3)**2
#Results
print "\n\n Result \n\n"
print "\n (a)current through 2 ohm resistor is ",round(I2,2)," A"
print "\n (b)power dissipated in the 3 ohm resistor is ",round(P3,2)," W"