# CHAPTER 2.9: LOAD FLOW STUDY USING COMPUTER TECHNIQUES¶

## Example 2.9.1, Page number 235-236¶

In [1]:
import scipy
from numpy import array

#Variable declaration
Z_L1 = complex(14.3,97)       #Series impedance of line L1(ohm)
Z_PL1 = complex(0,-3274)      #Shunt impedance of line L1(ohm)
Z_L2 = complex(7.13,48.6)     #Series impedance of line L2(ohm)
Z_PL2 = complex(0,-6547)      #Shunt impedance of line L2(ohm)
Z_L3 = complex(9.38,64)       #Series impedance of line L3(ohm)
Z_PL3 = complex(0,-4976)      #Shunt impedance of line L3(ohm)

#Calculation
Y_bus = [[Y_11, Y_12, Y_13],
[Y_21, Y_22, Y_23],
[Y_31, Y_32, Y_33]]

#Result
print('[Y_bus] = \n')
print(array(Y_bus))

[Y_bus] =

[[ 0.00444257-0.02977441j -0.00148749+0.01008999j -0.00295508+0.0201426j ]
[-0.00148749+0.01008999j  0.00372938-0.02488001j -0.00224188+0.01529642j]
[-0.00295508+0.0201426j  -0.00224188+0.01529642j  0.00519696-0.03508532j]]


## Example 2.9.2, Page number 236¶

In [1]:
import scipy
from numpy import array
from sympy import Symbol

#Variable declaration
Z_2 = complex(0,0.2)          #Impedance(ohm)
Z_5 = complex(0,0.4)          #Impedance(ohm)
Z_8 = complex(0,0.2)          #Impedance(ohm)

#Calculation
V_1 = Symbol('V_1')               #Voltage
V_2 = Symbol('V_2')               #Voltage
V_3 = Symbol('V_3')               #Voltage
I_1 = (Y_1+Y_2+Y_4+Y_5)*V_1-Y_2*V_2-Y_5*V_3     #Bus current
I_2 = -Y_2*V_1+(Y_2+Y_3+Y_8+Y_9)*V_2-Y_8*V_3    #Bus current
I_3 = -Y_5*V_1-Y_8*V_2+(Y_5+Y_6+Y_7+Y_8)*V_3    #Bus current

#Result
print('[Y_bus] = [[-j7.44  j5.0   j2.5]')
print('           [j5.0   -j9.96  j5.0]')
print('           [j5.0    j5.0   -j7.42]]')

[Y_bus] = [[-j7.44  j5.0   j2.5]
[j5.0   -j9.96  j5.0]
[j5.0    j5.0   -j7.42]]


## Example 2.9.3, Page number 236-237¶

In [1]:
import math
import cmath
import scipy
from numpy import array,linalg

#Variable declaration
V_a = 1.0                                   #Voltage(p.u)
V_b = 1.0*cmath.exp(1j*-36.87*math.pi/180)  #Voltage(p.u)
V_c = 1.0                                   #Voltage(p.u)
Z_1 = complex(0,1)                          #Reactance(p.u)
Z_2 = complex(0,1)                          #Reactance(p.u)
Z_3 = complex(0,1)                          #Reactance(p.u)
Z_13 = complex(0,0.4)                       #Reactance(p.u)
Z_23 = complex(0,0.4)                       #Reactance(p.u)
Z_14 = complex(0,0.2)                       #Reactance(p.u)
Z_24 = complex(0,0.2)                       #Reactance(p.u)
Z_34 = complex(0,0.2)                       #Reactance(p.u)
Z_12 = complex(0,0)                         #Reactance(p.u)

#Calculation
I_1 = V_a/Z_1         #Current injection vector(p.u)
I_2 = V_b/Z_2         #Current injection vector(p.u)
I_3 = V_c/Z_3         #Current injection vector(p.u)
I_4 = 0.0             #Current injection vector(p.u)
Y_bus = [[Y_11, Y_12, Y_13, Y_14],
[Y_21, Y_22, Y_23, Y_24],
[Y_31, Y_32, Y_33, Y_34],
[Y_41, Y_42, Y_43, Y_44]]                #Bus admittance matrix
Y_bus_inv = linalg.inv(Y_bus)                     #Inverse of bus admittance matrix
I = array([[I_1],
[I_2],
[I_3],
[I_4]])                                      #Current matrix
def MatrixMul( mtx_a, mtx_b):
tpos_b = zip( *mtx_b)
rtn = [[ sum( ea*eb for ea,eb in zip(Y_bus_inv,I)) for I in tpos_b] for Y_bus_inv in mtx_a]
return rtn
v = MatrixMul( Y_bus_inv, I )
V = array(v)

#Result
print('Voltage at bus 1, V_1 = %.4f%.4fj p.u' %(V[0,0].real,V[0,0].imag))
print('Voltage at bus 2, V_2 = %.4f%.4fj p.u' %(V[1,0].real,V[1,0].imag))
print('Voltage at bus 3, V_3 = %.4f%.4fj p.u' %(V[2,0].real,V[2,0].imag))
print('Voltage at bus 4, V_4 = %.4f%.4fj p.u' %(V[3,0].real,V[3,0].imag))
print('\nNOTE: Node equation matrix could not be represented in a single equation. Hence, it is not displayed')

Voltage at bus 1, V_1 = 0.9426-0.1721j p.u
Voltage at bus 2, V_2 = 0.9191-0.2427j p.u
Voltage at bus 3, V_3 = 0.9383-0.1852j p.u
Voltage at bus 4, V_4 = 0.9333-0.2000j p.u

NOTE: Node equation matrix could not be represented in a single equation. Hence, it is not displayed


## Example 2.9.4, Page number 237-238¶

In [1]:
import math
import cmath
import scipy
from numpy import array,linalg

#Variable declaration
V_a = 1.0                                   #Voltage(p.u)
V_b = 1.0*cmath.exp(1j*-36.87*math.pi/180)  #Voltage(p.u)
V_c = 1.0                                   #Voltage(p.u)
Z_1 = complex(0,1)                          #Reactance(p.u)
Z_2 = complex(0,1)                          #Reactance(p.u)
Z_3 = complex(0,1)                          #Reactance(p.u)
Z_13 = complex(0,0.4)                       #Reactance(p.u)
Z_23 = complex(0,0.4)                       #Reactance(p.u)
Z_14 = complex(0,0.2)                       #Reactance(p.u)
Z_24 = complex(0,0.2)                       #Reactance(p.u)
Z_34 = complex(0,0.2)                       #Reactance(p.u)
Z_12 = complex(0,0)                         #Reactance(p.u)

#Calculation
I_1 = V_a/Z_1         #Current injection vector(p.u)
I_2 = V_b/Z_2         #Current injection vector(p.u)
I_3 = V_c/Z_3         #Current injection vector(p.u)
I_4 = 0.0             #Current injection vector(p.u)
Y_bus = array([[Y_11, Y_12, Y_13, Y_14],
[Y_21, Y_22, Y_23, Y_24],
[Y_31, Y_32, Y_33, Y_34],
[Y_41, Y_42, Y_43, Y_44]])                #Bus admittance matrix
K = Y_bus[0:2,0:2]
L = Y_bus[0:2,2:4]
N = Y_bus[2:4,0:2]
M = Y_bus[2:4,2:4]
M_inv = linalg.inv(M)                              #Inverse of matrix M
def MatrixMul( mtx_a, mtx_b):
tpos_b = zip( *mtx_b)
rtn = [[ sum( ea*eb for ea,eb in zip(M_inv,N)) for N in tpos_b] for M_inv in mtx_a]
return rtn
v = MatrixMul( M_inv, N )                          #Multiplication of marix [M^-1][N]
def MatrixMul( mtx_a, mtx_b):
tpos_b = zip( *mtx_b)
rtn = [[ sum( ea*eb for ea,eb in zip(L,v)) for v in tpos_b] for L in mtx_a]
return rtn
V = array(MatrixMul( L, v ))                       #Multiplication of marix [L][M^-1][N]
Y_bus_new = K-V                                    #New bus admittance matrix

#Result
print('[Y_bus]new = \n')
print(Y_bus_new)

[Y_bus]new =

[[ 0.-4.97321429j  0.+3.52678571j]
[ 0.+3.52678571j  0.-4.97321429j]]



## Example 2.9.5, Page number 238¶

In [1]:
import math
import cmath
import scipy
from numpy import array,linalg

#Variable declaration
I_1 = 2.0                                   #Voltage(p.u)
I_2 = 2.0*cmath.exp(1j*45.0*math.pi/180)    #Voltage(p.u)

#Calculation
E_1 = I_1*y1                           #Voltage element(p.u)
E_2 = I_2*y2                           #Voltage element(p.u)
Y_bus = [[Y_11, Y_12],
Y_bus_inv = linalg.inv(Y_bus)          #Inverse of bus admittance matrix
I = [[I_1],
[I_2]]                        #Current matrix
def MatrixMul( mtx_a, mtx_b):
tpos_b = zip( *mtx_b)
rtn = [[ sum( ea*eb for ea,eb in zip(Y_bus_inv,I)) for I in tpos_b] for Y_bus_inv in mtx_a]
return rtn
V = array(MatrixMul( Y_bus_inv, I ))     #Multiplication of marix [Y_bus^-1][I]
V_1 = V[0,0]                             #Voltage(p.u)
V_2 = V[1,0]                             #Voltage(p.u)

#Result
print('Impedance elements in the impedance diagram are:')
print('  E_1 = %.f∠%.f° p.u' %(abs(E_1),cmath.phase(E_1)*180/math.pi))
print('  E_2 = %.f∠%.f° p.u' %(abs(E_2),cmath.phase(E_2)*180/math.pi))
print('  Y_11 = %.1fj p.u' %Y_11.imag)
print('  Y_12 = Y_21 = %.1fj p.u' %Y_12.imag)
print('  Y_22 = %.1fj p.u' %Y_22.imag)
print('V_1 = %.3f∠%.1f° p.u' %(abs(V_1),cmath.phase(V_1)*180/math.pi))
print('V_2 = %.3f∠%.1f° p.u' %(abs(V_2),cmath.phase(V_2)*180/math.pi))
print('\nNOTE: ERROR: Calculation mistake in V_1 in textbook')

Impedance elements in the impedance diagram are:
E_1 = 2∠-90° p.u
E_2 = 4∠-45° p.u
Y_11 = -3.0j p.u
Y_12 = Y_21 = 2.0j p.u
Y_22 = -4.0j p.u
V_1 = 1.399∠104.6° p.u
V_2 = 1.159∠117.2° p.u

NOTE: ERROR: Calculation mistake in V_1 in textbook


## Example 2.9.6, Page number 238¶

In [1]:
import scipy
from numpy import array,linalg

#Variable declaration
Y_bus = [[-1j*10.5, 0, 1j*5.0, 1j*5.0],
[0, -1j*8.0, 1j*2.5, 1j*5.0],
[1j*5.0, 1j*2.5, -1j*18.0, 1j*10.0],
[1j*5.0, 1j*5.0, 1j*10.0, -1j*20.0]]          #Bus admittance matrix

#Calculation
Z_bus = linalg.inv(Y_bus)                              #Bus impedance matrix

#Result
print('[Z_bus] = \n')
print(array(Z_bus))

[Z_bus] =

[[ 0.+0.72386446j  0.+0.62004326j  0.+0.65609229j  0.+0.66402307j]
[ 0.+0.62004326j  0.+0.73828407j  0.+0.64167267j  0.+0.66041817j]
[ 0.+0.65609229j  0.+0.64167267j  0.+0.70223504j  0.+0.67555876j]
[ 0.+0.66402307j  0.+0.66041817j  0.+0.67555876j  0.+0.71888969j]]


## Example 2.9.7, Page number 239¶

In [1]:
import scipy
from numpy import array

#Variable declaration
Z_L = complex(0,0.2)              #Series impedance(mho)

#Calculation
Y_bus = array([[Y_11, Y_12, Y_13],
[Y_21, Y_22, Y_23],
[Y_31, Y_32, Y_33]])     #Bus admittance matrix
S_11 = Y_bus[0,0].conjugate()
S_12 = Y_bus[0,1].conjugate()
S_13 = Y_bus[0,2].conjugate()
S_21 = S_12
S_22 = Y_bus[1,1].conjugate()
S_23 = Y_bus[1,2].conjugate()
S_31 = S_13
S_32 = S_23
S_33 = Y_bus[2,2].conjugate()

#Result
print('Power flow expressions are:')
print('S_1 = %.1fj|V_1|**2 %.1fjV_1*V_2(conj) %.1fjV_3(conj)' %(S_11.imag,S_12.imag,S_13.imag))
print('S_2 = %.1fjV_2*V_1(conj) + %.1fj|V_2|**2 %.1fjV_2*V_3(conj)' %(S_21.imag,S_22.imag,S_23.imag))
print('S_3 = %.1fjV_3*V_1(conj) %.1fjV_3*V_2(conj) + %.1fj|V_3|**2' %(S_31.imag,S_32.imag,S_33.imag))

Power flow expressions are:
S_1 = 9.8j|V_1|**2 -5.0jV_1*V_2(conj) -5.0jV_3(conj)
S_2 = -5.0jV_2*V_1(conj) + 9.8j|V_2|**2 -5.0jV_2*V_3(conj)
S_3 = -5.0jV_3*V_1(conj) -5.0jV_3*V_2(conj) + 9.8j|V_3|**2


## Example 2.9.8, Page number 242¶

In [1]:
import math
import cmath

#Variable declaration
V_1 = 1.0                        #Voltage(p.u)
S_g2 = complex(0,1.0)            #Complex power generated(p.u)
S_D2 = complex(0.5,1.0)          #Complex power demand(p.u)
Z_L = complex(0,0.5)             #Impedance(p.u)

#Calculation
S_2 = S_g2-S_D2
V_2_0 = 1.0                                           #Initial guess
V_2_1 = 1.0/Y_22*((S_2/V_2_0.conjugate())-Y_21*V_1)   #V_2(p.u). In 1st iteration
V_2_2 = 1.0/Y_22*((S_2/V_2_1.conjugate())-Y_21*V_1)   #V_2(p.u). In 2nd iteration
V_2_3 = 1.0/Y_22*((S_2/V_2_2.conjugate())-Y_21*V_1)   #V_2(p.u). In 3rd iteration
V_2_4 = 1.0/Y_22*((S_2/V_2_3.conjugate())-Y_21*V_1)   #V_2(p.u). In 4th iteration
V_2_5 = 1.0/Y_22*((S_2/V_2_4.conjugate())-Y_21*V_1)   #V_2(p.u). In 5th iteration
V_2_6 = 1.0/Y_22*((S_2/V_2_5.conjugate())-Y_21*V_1)   #V_2(p.u). In 6th iteration

#Result
print('By G-S method, V_2 = %.6f∠%.5f° p.u' %(abs(V_2_6),cmath.phase(V_2_6)*180/math.pi))

By G-S method, V_2 = 0.965948∠-14.99508° p.u


## Example 2.9.9, Page number 243-244¶

In [1]:
import math
import cmath

#Variable declaration
V_1 = 1.0                        #Voltage(p.u)
S_D2 = complex(1.0,0.5)          #Complex power demand(p.u)
Z_L = complex(0,0.5)             #Reactance(p.u)

#Calculation
V_2_0 = 1.0                      #Initial guess
Q_2_0 = 2.0*(1-V_2_0.real)
V_2_1 = 1+((0.75+1j*Q_2_0)/(Y_21*V_2_0.conjugate()))   #V_2(p.u). In 1st iteration
Q_2_1 = 2.0*(1-V_2_1.real)
V_2_2 = 1+((0.75+1j*Q_2_1)/(Y_21*V_2_1.conjugate()))   #V_2(p.u). In 2nd iteration
Q_2_2 = 2.0*(1-V_2_2.real)
V_2_3 = 1+((0.75+1j*Q_2_2)/(Y_21*V_2_2.conjugate()))   #V_2(p.u). In 3rd iteration
Q_2_3 = 2.0*(1-V_2_2.real)
V_2_4 = 1+((0.75+1j*Q_2_3)/(Y_21*V_2_3.conjugate()))   #V_2(p.u). In 4th iteration
Q_2_4 = 2.0*(1-V_2_2.real)
V_2_5 = 1+((0.75+1j*Q_2_4)/(Y_21*V_2_4.conjugate()))   #V_2(p.u). In 5th iteration

#Result
print('Q_2 = %.4f p.u' %(abs(Q_2_4)))
print('V_2 = %.4f∠%.4f° p.u' %(abs(V_2_5),cmath.phase(V_2_5)*180/math.pi))
print('\nNOTE: ERROR: Changes in the answer is due to substituition mistake in the textbook')

Q_2 = 0.2466 p.u
V_2 = 1.0539∠-21.1868° p.u

NOTE: ERROR: Changes in the answer is due to substituition mistake in the textbook


## Example 2.9.10, Page number 244¶

In [1]:
import math
import cmath

#Variable declaration
V_1 = 1.3                        #Voltage at bus 1(p.u)
V_3 = 1.0                        #Voltage at bus 3(p.u)
V_4 = 1.0                        #Voltage at bus 4(p.u)
S_2 = complex(0.5,-0.2)          #Power(p.u)

#Calculation
S_2_0_conj = S_2.conjugate()       #P_2-jQ_2(p.u)
V_2_0 = 1.0                        #Initial guess
V_2_1 = 1.0/Y_22*((S_2_0_conj/V_2_0.conjugate())-Y_21*V_1-Y_23*V_3-Y_24*V_4)   #V_2(p.u). In 1st iteration

#Result
print('After 1st iteration, V_2 = %.3f∠%.3f° p.u' %(abs(V_2_1),cmath.phase(V_2_1)*180/math.pi))
print('\nNOTE: ERROR: Changes in the answer is due to wrong substituition for V_1 i.e bus 1 voltage')

After 1st iteration, V_2 = 1.162∠2.285° p.u

NOTE: ERROR: Changes in the answer is due to wrong substituition for V_1 i.e bus 1 voltage