In [4]:

```
import math
from sympy import Symbol,solve
from scipy.misc import derivative
# Variables
NC = 24.; #Number Of Customers Per Block
#We get the Total Annual Cost from the releveant equations as
# TAC = 239.32 + (3.1805*ST) + (3492/ST) + (28170/ST**2) + (0.405*ASL) + (17018/ASL) + (1.134*ASD) + (8273/ASD)
#We know split the above equation into 3 different parts according to factors ST,ASD,ASL
#Variable Values of the Factors
ST = Symbol('ST');
ASD = Symbol('ASD');
ASL = Symbol('ASL');
#Functions to Find the TAC corresponding to the Respective Factors
def TransSize(y):
return 239.52 + (3.1805*y) + (3492./y) + (28170./(y**2))
def SDwire(y):
return (1.134*y)+(8273./y)
def SLwire(y):
return (0.405*y)+(17018./y)
#Total Annual Costs of the respective Factors
TACST = TransSize(ST);
TACASD = SDwire(ASD);
TACASL = SLwire(ASL);
#Partially Differentiating wrt ASD we get
#Y1 = derivative(TACASD);
#X1 = roots(Y1[1]);
X1 = [-85.413198,85.413198]
ASD = X1[0]; #Calculated Value
ASDstd = 105.500;
ASDstd1 = 133.1;
#Partially Differentiating wrt ASL we get
#Y2 = derivative(TACASL);
#X2 = solve(Y2[1]);
X2 = [-204.9872,204.9872 ]
ASL = X2[0]; #Calculated Value
ASLstd = 211.600;
ASLstd1 = 250.;
#Partially Differentiating wrt ST we get
#Y3 = derivative(TACST);
#X3 = solve(Y3[1]);
X3 = [39.346541,-19.673271 + 7.9480914j, -19.673271 - 7.9480914j, 0 ]
ST = round(X3[0]); #Calculated Value
STstd = 50.;
#Total Annual Cost of the Calculated parameters
TAC = TransSize(ST)+SDwire(ASD)+SLwire(ASL);
#Calculation Mistake in The Text Book
#Total Annual Cost of the First Higher standard Parameters
TACstd = TransSize(STstd)+SDwire(ASDstd)+SLwire(ASLstd);
#Total Annual Cost of the Second Higher standard Parameters
TACstd1 = TransSize(STstd)+SDwire(ASDstd1)+SLwire(ASLstd1);
#Total Fixed Charges per Year
TACFC = ((75+(2.178*STstd))+(5.4+(0.405*ASLstd))+(15.12+(1.134*ASD))+(144));
#Total Operating Charges per Year
TACOC = ((0.0225*STstd)+(0.98*STstd)+(28170/(STstd**2))+(3492/STstd)+(17018/ASLstd)+(8273/ASDstd));
#Values Might Vary from those in the text due to high precision
#Fixed Charges Per Customer Per Month
FC = TACFC/(NC*12);
#Variable Costs Per Customer per month
VOC = TACOC/(NC*12);
# Results
print 'a) The Most Economical SD Size is %g kmil and the nearest larger standard AWG wire size is %g kmil'%(ASD,ASDstd)
print 'b) The Most Economical SL Size is %g kmil and the nearest larger standard AWG wire size is %g kmil'%(ASL,ASLstd)
print 'c) The Most Economical Distribution Transformer Size is %g kmil and the nearest larger standard transformer\
size is %g kVA'%(ST,STstd)
print 'd) The Total Annual Cost Per Block for the theoretically most economical sizes of equipment is %g dollars'%(TAC)
print 'e) The Total Annual Cost Per Block for the nearest larger standard comercial sizes of equipment is %g dollars'%(TACstd)
print 'f) The Total Annual Cost Per Block for the nearest larger transformer size and for\
the second larger sizes of ASD and ASL is %g dollars'%(TACstd1)
print 'g) Fixed Charges per Customer per Month is %g dollars'%(FC)
print 'h) The Variable Operating Costs Per Customer Per Month is %g dollars'%(VOC)
```

In [3]:

```
import math
from numpy import matrix,multiply
#To determine the co-effcient matrix for a unbalanced load
#Page 304
# Variables
Dab = 12.;
Dan = 12.;
Dbn = 24.;
Daa = 12*0.01577;
Dbb = Daa;
Dnn = Daa;
# Calculations
def Coeff(y,z):
return (2*(10**-7))*math.log(y/z) #function to find the elements of the co-efficient matrix
#Part A of the question cannot be found using Scilab, Hence from the equation obtained in part A we can numerically compute the Co- Efficient Matrix
CM = matrix([[Coeff(Dan,Daa),Coeff(Dan,Dab)],[Coeff(Dbn,Dab),Coeff(Dbn,Dbb)],[Coeff(Dnn,Dan),Coeff(Dnn,Dbn)]]);
# Results
print ' Part A cannot be resulted by this code%( hence from the equations obtained in Part A Co-Efficient Matrix is Obtained as'
print (multiply(CM,(10**7)))
print ' * 10**-7 Wb*T/m'
```

In [4]:

```
import math
from numpy import matrix
from numpy.linalg import inv
# Variables
#Primary Voltage
V1 = 7272*(1j*math.pi*0/180);
#Secondary Voltages
Ea = 120*(1j*math.pi*0/180);
Eb = 120*(1j*math.pi*0/180);
#Impedances
Za = 0.8+(1j*0.6);
Zb = 0.8+(1j*0.6);
n = 60; #Turns Ratio
# Calculations
def angle(y):
return math.degrees(math.atan(y.imag/y.real))
#Substituting the values we get the following equations
#121.2 = Ia*(0.8857 + j0.6846) + Ib*(0.03279 + j0.03899)
#121.2 = Ia*(-0.03279 - j0.03899) + Ib*(-0.88574 + j0.50267)
#For Convenience We segregate them as
Z1 = (0.8857+(1j*0.6846));
Z2 = (0.03279+(1j*.03899))
Z3 = (-0.03279-(1j*.03899))
Z4 = (-0.88574+(1j*.50267))
Z = matrix([[Z1,Z2],[Z3,Z4]]); #Impedance matrix
V = matrix([[121.2],[121.2]]); #Voltage Matrix
I = inv(Z)*V; #Current Matrix
#Secondary Currents
Ia = I[0];
Ib = I[1];
In = -Ia-Ib; #Secondary neutral Currents
#Secondary Voltages
Va = Za*Ia;
Vb = -1*Zb*Ib;
#Secondary Voltage Resulmath.tant
Vab = Va+Vb;
# Results
print 'a The Secondary Currents are:'
print 'Ia = %g/_%g A'%(abs(Ia),angle(Ia))
print 'Ib = %g/_%g A'%(abs(Ib),180+angle(Ib))
print 'b) The Secondary Neutral Current = %g/_%g A'%(abs(In),angle(In))
print 'c The Secondary Voltages are:'
print 'Va = %g/_%g V'%(abs(Va),angle(Va))
print 'Vb = %g/_%g V'%(abs(Vb),angle(Vb))
print 'd) The Resulmath.tant Secondary Voltage Vab is %g/_%g V'%(abs(Vab),angle(Vab))
#In the TextBook Note That Zb has been taken wrong in the calculattion of Vb
```

In [5]:

```
import math
# Variables
N = 19.; #Number Transformers
St = 500.; #Load on each transformer in kVA
L = 5096+(1j*3158); #Load
Vlf = 114.; #Favourable Voltage
Vlt = 111.; #Tolerable Volatage
Vb = 125.; #Base Voltage
# Calculations
#Per Unit Tolerable and favourable voltages
puVlf = Vlf/Vb;
puVlt = Vlt/Vb;
ZM = 0.181+(1j*0.115); #The Positive Sequence Impedance
ZTi = 0.0086+(1j*0.0492); #Transformer Impedance for 500kVA
ZT = 2*ZTi; #Transformer Impedance for 1000kVA
AAF = N*St/abs(L); #Actual Application Factor
# Results
print 'a) The Lowest favourable Voltage is %g pu and The Lowest tolerable voltage is %g pu'%(puVlf,puVlt)
print 'b) There Are No buses in Table 6-5%( for the first contingency outage which satisfy the necessary condition'
print 'c For Second Contingency Outage'
print '1) Less than Favourable Voltage are B,C,J,K,R and S'
print '2) Less than Tolerable Voltage are B,C,J,K.'
print 'd) ZM/ZT = %g and 1/2)*ZM/ZT = %g respectively.'%(abs(ZM)/abs(ZT),((1./2)*abs(ZM)/abs(ZT)))
print 'The Actual Application Factor is %g'%(AAF)
print 'Therefore the Design of this network is sufficient'
```