import math
#initialisation of variables
C1=0.02*100
C2=0.05
Fs=100
S1=complex(0.41,-0.11)
S2=complex(-0.4, 0.10)
S3=complex(-.105,0.11)
S4=complex(-.105,.11)
S5=complex(0.14,-.14)
S6=complex(-0.7,.35)
Z12=complex(0.08,.24)
Z23=complex(0.06,.18)
Z31=complex(0.02,.06)
Z21=Z12
Z32=Z23
Z13=Z31
#Calculations
W1=(50*10**(-6))/((C1*abs(S1)+(C2*(Fs)))**2)
W2=(50*10**(-6))/((C1*abs(S2)+C2*(Fs))**2)
W3=(50*10**(-6))/((C1*abs(S3)+C2*(Fs))**2)
W4=(50*10**(-6))/((C1*abs(S4)+C2*(Fs))**2)
W5=(50*10**(-6))/((C1*abs(S5)+C2*(Fs))**2)
W6=(50*10**(-6))/((C1*abs(S6)+C2*(Fs))**2)
print("W1= %.2f" %W1) #Answers for W1,W2,W3,W4,W5,W6 in the book is wrongly Calculated
print("W2= %.2f" %W2)
print("W3= %.2f" %W3)
print("W4= %.2f" %W4)
print("W5= %.2f" %W5)
print("W6= %.2f" %W6)
a1=W1/(abs(13)**2)
[D]=diag([W1/(abs(Z13)**2)W2/(abs(Z31)**2)W3/(abs(Z12)**2)W4/(abs(Z21)**2)W5/(abs(Z23)**2)W6/(abs(Z32)**2)])
A=[-1 0 11 0 -11 -1 0-1 1 00 1 -10 -1 1]
B=[-1 01 01 -1-1 10 10 -1]
b=[1-100-11]
C=(B')*D#Assuming Transpose(B)D=C
F=(B')*D*B#Assuming Transpose(B)*D*B=F
G=(inv(F))*C#Assuming(BTDB)-1*(BT)*D=F
E1=1.05
E2=E1
E3=E1
invH=diag([Z31/E3Z13/E1Z12/E1Z21/E2Z23/E2Z32/E2])
Sm=[.41+%i*.11-.4-%i*.1-.105-%i*.11.14+%i*.14.72+%i*.37-.7+%i*.35]
EMo=invH*Sm
a=EMo-b*E1
E=G*a
#Results
print(E,"E=") #Answers differs due to wrong calculation of W1,W2,W3,W4,W5,W6
import math
#initialisation of variables
X=.625
P=1.0
Q=0.6
V=1.0
#Calculations
Eth=V+(Q*X/V)+complex(P*X/V)
Phase_Eth=math.degrees(math.atan(Eth.imag/Eth.real))
#Results
print("Eth=%.2f at an angle %.0f degrees" %(abs(Eth),Phase_Eth))
import math
#initialisation of variables
P=0.5
toff=4.0
#Calculations
ton=(P*toff-0*toff)/(0.8-P)
#Results
print("Toff= 4min .")
print("ton(min.)=%.3f min." %ton)
import math
#initialisation of variables
V=1.0
Qload=1.0*V
Qcap=-0.75*V**2
#Calculations
Qnet=Qload+Qcap
VS=1-0.75*2*V # voltage sensitivity
#Results
print("Voltage sensitivity=%.3f" %VS)
print("since the voltage sensitivity is negative,\nvoltage regulation by tap changing will reduce net reactive load and improive voltage stability ")
import math
#initialisation of variables
Y=complex(-10)
n=1+0.1
#Calculations
Y1=n*(n-1)*Y
Y2=(1-n)*Y
#Results
print("Y1= {0:.2f}+{1:.2f}i".format(Y1.real, Y1.imag))
print("Y2= {0:.2f}+{1:.2f}i".format(Y2.real, Y2.imag))
print("The shunt elements equal to a reactor of 1.1V1^2 size oin the primary side and a capacitive of sixe 1V2**2 on the secondary side")
import math
#initialisation of variables
P=1.0 #assuming
S1=P/.95 #For pf .95
S2=P/.8 #For pf .8
#Calculations
dMVA=(S2-S1)*100.0/P #Increase in MVA rating
Q1=P*math.tan(math.radians(math.degrees(math.acos(0.95)))) #Q for pf .95
Q2=P*math.tan(math.radians(math.degrees(math.acos(0.8)))) #Q for pf .8
dPc=(Q2-Q1)*100.0/Q1 #Percent additional Reactive Power Capability
#Results
print("Percent additional Reactive Power Capability is %.2f" %dPc)