import math
import numpy
#initialisation of variables
E1=complex(100,0)
E2=complex(86.6,50)
Z=complex(5)
X=5.0
print(" Value of voltage source one designated as a machine 1 = {0:.5f}+{1:.5f}i v".format(E1.real, E1.imag))
print(" Value of voltage source two designated as a machine 2 = {0:.5f}+{1:.5f}i v".format(E2.real, E2.imag))
print(" Impedance connected = %.4f ohms " %abs(Z))
#Calculation Of Current
I=(E1-E2)/Z
print(" Current through the impedance = {0:.5f}+{1:.5f}i A".format(I.real, I.imag))
#Calculations
#Calculation Of Power
M1=E1*numpy.conj(I)
print('Machine one Power = %.2f' %M1)
M2=E2*numpy.conj(I)
print('Machine Two Power = %.2f' %M2)
#Calculation Of Reactive Power Required By Inductive Reactance
RP=(abs(I))**2*X
print(" Reactive power required by inductive reactance i.e, impedance = %.4f VAR " %RP)
print(" Machine 1 consumes energy at the rate of %.4f W " %abs(M1.real))
print(" Machine 2 generates energy at the rate of %.4f W " %abs(M2.real))
print(" Machine 1 supplies reactive power at the rate of %.4f VAR " %(M1.imag))
print(" Machine 2 supplies reactive power at the rate of %.4f VAR " %abs(M2.imag))
print(" Reactive power required by inductive reactance i.e, impedance = Sum of reactive power supplied by machine 1 + reactive power supplied by machine 2 = %.4f VAR "%RP)
print('Real Power consumed by impedance is Zero')
print('The real power generated by machine two is transferred to machine one')
import math
#initialisation of variables
Vab = 173.2*complex(math.cos(0),math.sin(0))
Vbc = 173.2*complex(math.cos(240*math.pi/180),math.sin(240*math.pi/180))
Vca = 173.2*complex(math.cos(120*math.pi/180),math.sin(120*math.pi/180))
print('The given line-line voltages are')
#'/_' this symbol has been used to show angle
print( "Vab= {0:.2f}".format(abs(Vab.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Vab.imag,Vab.real))*180/math.pi))
print( "Vbc= {0:.2f}".format(abs(Vbc)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Vbc.imag,Vbc.real))))
print( "Vca= {0:.2f}".format(abs(Vca)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Vca.imag,Vca.real))))
#Calculation of line-neutral voltage
Van = (Vab/math.sqrt(3)/complex(0.866,0.5))
Vbn = (Vbc/math.sqrt(3)/complex(0.866,0.5))
Vcn = (Vca/math.sqrt(3)/complex(0.866,0.5))
print('The line-neutral voltages are')
print( "Van= {0:.2f}".format(abs(Van.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Van.imag,Van.real))*180/math.pi))
print( "Vbn= {0:.2f}".format(abs(Vbn)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Vbn.imag,Vbn.real))))
print( "Vcn= {0:.2f}".format(abs(Vcn)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Vcn.imag,Vcn.real))))
ZL = 10*complex(math.cos(20*math.pi/180),math.sin(20*math.pi/180))
print( "Load Impedance ZL = {0:.2f}".format(abs(ZL)))
print("Angle = %.2f v " %(math.degrees(math.atan2(ZL.imag,ZL.real))))
#Calculation of line-neutral current
Ian = Van / ZL
Ibn = Vbn / ZL
Icn = Vcn / ZL
#Results
print('The resulting current in each phase')
print( "Ian= {0:.2f}".format(abs(Ian.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Ian.imag,Ian.real))*180/math.pi))
print( "Ibn= {0:.2f}".format(abs(Ibn)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Vbn.imag,Vbn.real))))
print( "Icn= {0:.2f}".format(abs(Icn)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Icn.imag,Icn.real))))
import math
#initialisation of variables
Vll = 4.4e3
Vln=Vll /math.sqrt(3)
Zline=1.4*complex(math.cos(75* math.pi/180),math.sin(75*math.pi/180))
Van = Vln*complex(math.cos(0),math.sin(0))
Zload = 20*complex(math.cos(30*math.pi/180),math.sin(30*math.pi/180))
print(" Given line-line voltage = %.4f V " %Vll)
print(" Line-neutral voltage = %.4f V " %Vln)
#'/_' this symbol has been used to specify angle
print( "Impedance of the load = {0:.2f}".format(abs(Zload.real)))
print("Angle = %.2f ohms " %(math.degrees(math.atan2(Zload.imag,Zload.real))))
print( "Impedance of the line = {0:.2f}".format(abs(Zline.real)))
print("Angle = %.2f ohms " %(math.degrees(math.atan2(Zline.imag,Zline.real))))
#Calculation of phase current
Ian = Van / Zload
print( "Van = {0:.2f}".format(abs(Van.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Van.imag,Van.real))))
print( "Ian = {0:.2f}".format(abs(Ian.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Ian.imag,Ian.real))))
#Calculation of line-neutral voltage at the substation
Vltn = Van + Ian * Zline
#Magnitude of the voltage at the substation bus
magVl = math.sqrt(3) * abs(Vltn)
#Results
print( "The line to neutral voltage at the substation = {0:.2f} ".format(abs(Vltn.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Vltn.imag,Vltn.real))))
print(" The magnitude of the voltage at the substation bus = %.4f V" %magVl)
import math
#initialisation of variables
Vll = 4.4e3
Zline = 1.4*complex(math.cos(75*math.pi/180),math.sin(75*math.pi/180))
Zload = 20*complex(math.cos(30*math.pi/180),math.sin(30*math.pi/180))
Vbase = Vll
Ibase = 127
Zbase = (Vbase / math.sqrt(3)) / Ibase
#Calculations
#Displaying the given values and the base values
print(" Given line-line voltage = %.4f V " %Vll)
print( "Impedance of the load = {0:.2f}".format(abs(Zload.real)))
print("Angle = %.2f ohms " %(math.degrees(math.atan2(Zload.imag,Zload.real))))
print( "Impedance of the line = {0:.2f}".format(abs(Zline.real)))
print("Angle = %.2f ohms " %(math.degrees(math.atan2(Zline.imag,Zline.real))))
print(" Base Voltage = %.4f V " %Vbase)
print(" Base Current = %.4f V " %Ibase)
print(" Base Impedance = %.4f V " %Zbase)
Van = (Vll/math.sqrt(3))*complex(math.cos(0),math.sin(0))
Ian = Van / Zload
print( "Van = {0:.2f}".format(abs(Van.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Van.imag,Van.real))))
print( "Ian = {0:.2f}".format(abs(Ian.real)))
print("Angle = %.2f v " %(math.degrees(math.atan2(Ian.imag,Ian.real))))
#Calculation of per-unit quantities
V_pu = Vll / Vbase
I_pu = Ian / Ibase
Zline_pu = Zline / Zbase
Zload_pu = Zload / Zbase
Van_pu = V_pu + I_pu * Zline_pu
print('Per-unit Quantities')
print( "Per Unit line-line voltage = {0:.2f}".format(abs(V_pu.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(V_pu.imag,V_pu.real))))
print( "Per Unit line-neutral current = {0:.2f}".format(abs(I_pu.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(I_pu.imag,I_pu.real))))
print( "Per Unit line-neutral voltage = {0:.2f}".format(abs(V_pu.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(Van_pu.imag,Van_pu.real))))
print( "Per Unit line impedance = {0:.2f}".format(abs(Zline_pu.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(Zline_pu.imag,Zline_pu.real))))
print( "Per Unit load impedance = {0:.2f}".format(abs(Zload_pu.real)))
print("Angle = %.2f per unit " %(math.degrees(math.atan2(Zload_pu.imag,Zload_pu.real))))
#Calculation of line-neutral and line-line voltage
Vln = abs(Van_pu) * Vll / math.sqrt(3)
VLL = abs(Van_pu) * Vll
#Results
print( "The line to neutral voltage at the substation , VLN = {0:.2f}".format(abs(Vln.real)))
print("Angle = %.2f V " %(math.degrees(math.atan2(Vln.imag,Vln.real))))
print(" The magnitude of the voltage at the substation bus , VLL= %.4f V" %VLL)
import math
#initialisation of variables
pu_Z_given = 0.25
base_kV_given = 18
base_kV_new = 20.0
base_kVA_new = 100.0
base_kVA_given = 500.0
#Calculations
X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given))
#Results
print('Per-Unit Znew = per-unit Zgiven * (base kVgiven/base kVnew)**2 * (base kVAnew/base kVAgiven)')
print(' = 0.25 * (18/20)**2 * (100/500)')
print(" Per-Unit Znew = %.4f per unit" %X11)