#calculate A,B,C,D
import math
import cmath
import numpy
#Given data :
r=0.22##ohm
x=0.45##ohm
g=4.*10.**-9##S
b=2.53*10.**-6##S
f=50.##Hz
l=1000.##Km
#Using Convergent series of complex angles
z=r+1j*x##ohm
y=g+1j*b##ohm
Z=z*l##ohm
Y=y*l##ohm
YZ=Y*Z##ohm
Y2Z2=YZ**2.##ohm
Y3Z3=YZ**3.##ohm
A=1.+YZ/2.+Y2Z2/24.+Y3Z3/720.##ohm
D=A##oh,m
B=Z*(1.+YZ/6.+Y2Z2/120.+Y3Z3/5040.)##ohm
C=Y*(1.+YZ/6.+Y2Z2/120.+Y3Z3/5040.)##ohm
print '%s' %("Auxiliary Constants by using Convergent series of complex angles : ")#
print "A = ",A#
print "B = ",B#
print "C = ",C#
#Using Convergent series of real angles
A=cmath.cosh(cmath.sqrt(YZ))##ohm
D=A##ohm
B=cmath.sqrt(Z/Y)*cmath.sinh(cmath.sqrt(YZ))##ohm
C=cmath.sqrt(Y/Z)*cmath.sinh(cmath.sqrt(YZ))##ohm
A=cmath.cosh(cmath.sqrt(YZ))##ohm
print '%s' %("Auxiliary Constants by using Convergent series of real angles : ")#
print '%s %.2f %s %.2f' %("A, magnitude is ",abs(A)," and angle in degree is ",cmath.phase(A)*180/math.pi)#
print '%s %.2f %s %.2f' %("B, magnitude is ",abs(B)," and angle in degree is ",cmath.phase(B)*180/math.pi)#
print '%s %.4f %s %.2f' %("C, magnitude is ",abs(C)," and angle in degree is ",cmath.phase(C)*180/math.pi)#
print '%s' %("We obtain same result by both of the methods.")
#calculate Sending end line voltage in kV,Sending end current in A, magnitude is
import math
import cmath
#Given data :
Z=200.*(math.cos(80.*math.pi/180.) + 1j*math.sin(80.*math.pi/180.))##ohm
Y=0.0013*(math.cos(90.*math.pi/180.) + 1j*math.sin(90.*math.pi/180.))#S/phase
P=80.*10.**6##W
pf=0.8##power factor
VRL=220.*1000.##V
VR=VRL/math.sqrt(3.)##V
IR=P/math.sqrt(3.)/VRL/pf##A
fi=math.acos(pf)*180/math.pi##degree
IR=IR*(math.cos(-fi*math.pi/180.) + 1j*math.sin(-fi*math.pi/180.))##A
YZ=Y*Z##ohm
Y2Z2=YZ**2##ohm
Y3Z3=YZ**3##ohm
A=1.+YZ/2.+Y2Z2/24+Y3Z3/720##ohm
D=A##oh,m
B=Z*(1.+YZ/6.+Y2Z2/120.+Y3Z3/5040.)##ohm
C=Y*(1.+YZ/6.+Y2Z2/120.+Y3Z3/5040.)##mho
VS=A*VR+B*IR##V
VSL=math.sqrt(3.)*abs(VS)##V
print '%s %.2f' %("Sending end line voltage in kV : ",VSL/1000.)#
IS=C*VR+D*IR##
print '%s %.2f %s %.2f' %("Sending end current in A, magnitude is ",abs(IS)," and angle in degree is ",cmath.phase(IS)*180/math.pi)#
#calculate Constant A0,Constant B0,Constant C0,Constant D0
import math
import cmath
#Given data :
VRL=220.##kV
VR=VRL/math.sqrt(3.)##V
P=10.*10**6##VA
Z=1.+1j*8.##ohm(in %)
Zse=Z/100.*VRL**2./100.##ohm/phase
A=0.9*(math.cos(0.6*math.pi/180.) + 1j*math.sin(0.6*math.pi/180.))##Auxiliary constant
D=A ##Auxiliary constant
B=153.2*(math.cos(84.6*math.pi/180.) + 1j*math.sin(84.6*math.pi/180.))##Auxiliary constant
C=0.0012*(math.cos(90*math.pi/180.) + 1j*math.sin(90*math.pi/180.))##Auxiliary constant
A0=A+C*Zse##constant
B0=B+D*Zse##ohm#constant
C0=C##mho or S#constant
D0=A##constant
print '%s %.4f %s %.2f' %("Constant A0, magnitude is ",abs(A0)," and angle in degree is ",cmath.phase(A0)*180/math.pi)#
print '%s %.f %s %.2f' %("Constant B0(ohm), magnitude is ",abs(B0)," and angle in degree is ",cmath.phase(B0)*180/math.pi)#
print '%s %.4f %s %.2f' %("Constant C0(S), magnitude is ",abs(C0)," and angle in degree is ",cmath.phase(C0)*180/math.pi)#
print '%s %.1f %s %.2f' %("Constant D0, magnitude is ",abs(D0)," and angle in degree is ",cmath.phase(D0)*180/math.pi)#
#calculate Constant A0,Constant B0,Constant C0,Constant D0
import math
import cmath
#Given data :
A=0.98*(math.cos(2.*math.pi/180.) + 1j*math.sin(2.*math.pi/180.))##Auxiliary constant
D=A##Auxiliary constant
B=28.*(math.cos(69.*math.pi/180.) + 1j*math.sin(69.*math.pi/180.))##Auxiliary constant
Zse=12.*(math.cos(80.*math.pi/180.) + 1j*math.sin(80.*math.pi/180.))##ohm
C=(A*D-1)/B##Auxiliary constant
A0=A+C*Zse##constant
B0=B+2.*A*Zse+C*Zse**2.##ohm#constant
C0=C##mho or S#constant
D0=A0##constant
print '%s %.2f %s %.2f' %("Constant A0, magnitude is ",abs(A0)," and angle in degree is ",cmath.phase(A0)*180/math.pi)#
print '%s %.2f %s %.2f' %("Constant B0(ohm), magnitude is ",abs(B0)," and angle in degree is ",cmath.phase(B0)*180/math.pi)#
print '%s %.2f %s %.f' %("Constant C0(S), magnitude is ",abs(C0)," and angle in degree is ",cmath.phase(C0)*180/math.pi)#
print '%s %.3f %s %.2f' %("Constant D0, magnitude is ",abs(D0)," and angle in degree is ",cmath.phase(D0)*180/math.pi)#
#calculate
import math
import cmath
#Given data :
A=0.92*(math.cos(5.3*math.pi/180.) + 1j*math.sin(5.3*math.pi/180.))#Auxiliary constant
D=A##Auxiliary constant
B=65.3*(math.cos(81*math.pi/180.) + 1j*math.sin(81*math.pi/180.))##Auxiliary constant
ZT=100*(math.cos(70*math.pi/180.) + 1j*math.sin(70*math.pi/180.))##ohm
YT=0.0002*(math.cos(-75.*math.pi/180.) + 1j*math.sin(-75.*math.pi/180.))##S
C=(A*D-1)/B##Auxiliary constant
A0=A*(1+2*YT*ZT)+B*(YT)+C*ZT*(1+YT*ZT)##constant
B0=2.*A*ZT+B+C*ZT**2##ohm#constant
C0=2.*A*YT*(1.+YT*ZT)+B*YT**2.+C*(1.+YT*ZT)**2.##mho or S#constant
D0=A0##constant
print '%s %.5f %s %.2f' %("Constant A0, magnitude is ",abs(A0)," and angle in degree is ",cmath.phase(A0)*180/math.pi)#
print '%s %.2f %s %.2f' %("Constant B0(ohm), magnitude is ",abs(B0)," and angle in degree is ",cmath.phase(B0)*180/math.pi)#
print '%s %.6f %s %.1f' %("Constant C0(S), magnitude is ",abs(C0)," and angle in degree is ",cmath.phase(C0)*180/math.pi)#
print '%s %.2f %s %.2f' %("Constant D0, magnitude is ",abs(D0)," and angle in degree is ",cmath.phase(D0)*180/math.pi)#
#calculate
import math
import cmath
#Given data :
A=0.945*math.cos(1.02*math.pi/180.) + 1j*math.sin(1.02*math.pi/180.)##Auxiliary constant
D=A##Auxiliary constant
B=82.3*math.cos(73.03*math.pi/180.) + 1j*math.sin(73.03*math.pi/180.)##ohm#Auxiliary constant
C=0.001376*math.cos(90.4*math.pi/180.) + 1j*math.sin(90.4*math.pi/180.)##S#Auxiliary constant
#part (i)
Y=C##S
Z=2.*(A-1)/C##ohm
print '%s' %("For equivalent T-network : ")#
print '%s %.6f %s %.1f' %("Shunt admittance in S, magnitude is ",abs(Y)," and angle in degree is ",cmath.phase(Y)*180/math.pi)#
print '%s %.2f %s %.1f' %("Impedance in ohm, magnitude is ",abs(Z)," and angle in degree is ",cmath.phase(Z)*180/math.pi)#
print '%s' %("For equivalent pi-network : ")#
Z=B##ohm
print '%s %.2f %s %.2f' %("Series Impedance in ohm, magnitude is ",abs(Z)," and angle in degree is ",cmath.phase(Z)*180/math.pi)#
Y=2.*(A-1)/B##S
print '%s %.6f %s %.2f' %("Shunt admittance in S, magnitude is ",abs(Y)," and angle in degree is ",cmath.phase(Y)*180/math.pi)#
#For T-Network Value of Z is wrog in the book.