import math
#initialisation of variables
#Voltage Sources
Ea = 1.5
Eb = 1.5*complex(math.cos(-36.87 * math.pi / 180),math.sin(-36.87 * math.pi / 180))
Ec = 1.5
#admittances
Ya = -complex(0.8)
Yb = Ya
Yc= Ya
Yd = -complex(5)
Ye = -complex(8)
Yf = -complex(4)
Yg = -complex(2.5)
Yh = Yd
#Calculations
#current sourcs
I1 = Ea * Ya
I2 = Eb * Yb
I3 = I1
I4 = 0
print('Current Sources are')
print(" I1 = - j%.2f per unit" %(-I1.imag))
print(" I2 = %.2f - j%.2f per unit" %(I2.real,-I2.imag))
print(" I3 = - j%.2f per unit " %(-I3.imag))
#Self-admittances
Y11 = Yd + Yf + Ya
Y22 = Yh + Yg + Yb
Y33 = Ye + Yc + Yg + Yf
Y44 = Yd + Ye + Yh
print('Self-admittances are')
print(" Y11 = - j%.2f per unit" %(-Y11.imag))
print(" Y22 = - j%.2f per unit" %(-Y22.imag))
print(" Y33 = - j%.2f per unit" %(-Y33.imag))
print(" Y44 = - j%.2f per unit" %(-Y44.imag))
#Mutual-admittances
Y12 = 0;Y21 = Y12
Y13 = -Yf;Y31 = Y13
Y14 = -Yd;Y41 = Y14
Y23 = -Yg;Y32 = Y23
Y24 = -Yh;Y42 = Y24;
Y34 = -Ye;Y43 = Y34
print('Mutual admittances are')
print(" Y12 = - j%.2f per unit" %(-Y12.imag))
print(" Y13 = - j%.2f per unit" %(-Y13.imag))
print(" Y14 = - j%.2f per unit" %(-Y14.imag))
print(" Y23 = - j%.2f per unit" %(-Y23.imag))
print(" Y24 = - j%.2f per unit" %(-Y24.imag))
print(" Y34 = - j%.2f per unit" %(-Y34.imag))
#Matrix Form
I = [I1.real,I2.imag,I3.real,I4.imag]
Y = [[Y11.real,Y12.real,Y13.real,Y14.real],
[Y21.real,Y22.real,Y23.real,Y24.real],
[Y31.real,Y32.real,Y33.real,Y34.real],
[Y41.real,Y42.real,Y43.real,Y44.real]]
print('Current Vector =')
for i in range(0, 4):
print("I= %.2f" %I[i])
print('Bus admittance matrix =')
for x in range(0, 4):
for y in range(0, 4):
print("Y[%.0f][%.0f]= %.2f" %(x,y,Y[x][y]))
print("\n")
import math
import numpy
#initialisation of variables
#Voltage Sources
Ea = 1.5
Eb = 1.5*complex(math.cos(-36.87*math.pi/180),math.sin(-36.87 * math.pi / 180))
Ec = 1.5;
#admittances
Ya = complex(-0.8)
Yb = Ya
Yc= Ya
Yd = complex(-5)
Ye = complex(-8)
Yf = complex(-4)
Yg = complex(-2.5)
Yh = Yd
#Calculations
#current sourcs
I1 = Ea * Ya
I2 = Eb * Yb
I3 = I1
I4 = 0
#Self-admittances
Y11 = Yd + Yf + Ya
Y22 = Yh + Yg + Yb
Y33 = Ye + Yc + Yg + Yf
Y44 = Yd + Ye + Yh
#Mutual-admittances
Y12 = 0
Y21 = Y12
Y13 = -Yf
Y31 = Y13
Y14 = -Yd
Y41 = Y14
Y23 = -Yg
Y32 = Y23
Y24 = -Yh
Y42 = Y24
Y34 = -Ye
Y43 = Y34
#Matrix Form
I = [I1,I2,I3,I4]
Y = [[Y11,Y12,Y13,Y14],[Y21,Y22,Y23,Y24],[Y31,Y32,Y33,Y34],[Y41,Y42,Y43,Y44]]
V = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
for x in range(0, 4):
for y in range(0, 4):
if I[x].imag > 0 :
V[x][y]=Y[x][y]/I[x]
else:
V[x][y]=0
#Results
print('Node Voltages V1,V2,V3 and V4 in per unit is')
for x in range(0, 4):
for y in range(0, 4):
print("V[%.0f][%.0f]= %.2f -%.2fi" %(x,y,V[x][y].imag,V[x][y].real))
print("\n")
print('In polar form')
print( "V1 = {0:.2f}".format(abs(V[0][0].real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(V[0][0].imag,V[0][0].real))*180/math.pi))
print( "V2 = {0:.2f}".format(abs(V[1][1].real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(V[1][1].imag,V[1][1].real))*180/math.pi))
print( "V2 = {0:.2f}".format(abs(V[2][2].real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(V[2][2].imag,V[2][2].real))*180/math.pi))
print( "V2 = {0:.2f}".format(abs(V[3][3].real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(V[3][3].imag,V[3][3].real))*180/math.pi))
import math
#initialisation of variables
Ea = 1.5
Eb = 1.5*complex(math.cos(-36.87 *math.pi / 180),math.sin(-36.87 * math.pi / 180))
Ec = 1.5
#admittances
Ya = -complex(0.8)
Yb = Ya
Yc= Ya
Yd = -complex(5)
Ye = -complex(8)
Yf = -complex(4)
Yg = -complex(2.5)
Yh = Yd
#Self-admittances
Y11 = Yd + Yf + Ya
Y22 = Yh + Yg + Yb
Y33 = Ye + Yg + Yf
Y44 = Yd + Ye + Yh
#Mutual-admittances
Y12 = 0
Y21 = Y12
Y13 = -Yf
Y31 = Y13
Y14 = -Yd
Y41 = Y14
Y23 = -Yg
Y32 = Y23
Y24 = -Yh
Y42 = Y24
Y34 = -Ye
Y43 = Y34
#Calculations
#Bus Impedance Matrix
Y = [[Y11,Y12,Y13,Y14],[Y21,Y22,Y23,Y24],[Y31,Y32,Y33,Y34],[Y41,Y42,Y43,Y44]]
K = [[Y[0][0],Y[0][1]],[Y[1][0],Y[1][1]]]
L = [[Y[0][2],Y[0][3]],[Y[1][2],Y[1][3]]]
L_T = [[Y[2][0],Y[2][1]],[Y[3][0],Y[3][1]]]
M = [[Y[2][2],Y[2][3]],[Y[3][2],Y[3][3]]]
Ybus = [[0,0],[0,0]]
M_1 = [[complex(0.0913706),complex(0.0406091)],[complex(0.0406091),complex(0.0736041)]]
LMT = [[complex(-4.9263959),complex(-4.0736041)],[complex(-4.0736041),complex(-3.4263959)]]
for x in range(0, 2):
for y in range(0, 2):
Ybus[x][y]=K[x][y]-LMT[x][y]
Y_12 = - Ybus[0][1]
Y_10 = Ybus[0][0] - Y_12
Y_20 = Y_10
print(" Admittance between buses 1 and 2 = - j%.4f per unit" %(-Y_12.imag))
print(" Admittance between buse 1 and reference bus = - j%.4f per unit" %(-Y_10.imag))
print(" Admittance between buse 2 and reference bus = - j%.4f per unit" %(-Y_20.imag))
Z = 1/Y_12 + 1/Y_10 + 1/Y_20
I = (Ea-Eb) / Z
print( "I = {0:.2f}".format(abs(I.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(I.imag,I.real))))
I1=complex(0.3278120,0.1092710)
Pa = Ea * I1
#Resluts
print(" Power out of source ''a'' = %.3f + j%.3f per unit " %(Pa.real,Pa.imag))
Pb = Eb * I1
print(" Power out of source ''b'' = %.3f - j%.3f per unit " %(Pb.real,-Pb.imag))
Var = (abs(I))**2 * (Z.imag)
print(" Reactie voltamperes in circuit equivalent = %.3f per unit " %Var)
V_1 = Ea - I/Y_10
print(" Voltage at node 1 = %.3f - j%.3f per unit " %(V_1.real,-V_1.imag))