Chapter 5 - Steady state sinusoidal analaysis

Pg: 181 Ex:5.1

In [1]:
from __future__ import division
from numpy import arange,cos,pi,sqrt
%matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show
R=50#
t=arange(0,0.05+0.000001,0.000001)
V_t=[]
for tt in t:
    V_t.append(100*cos(100*pi*tt))
V_m=100#      #peak value
V_rms=V_m/sqrt(2)#
P_avg=(V_rms**2)/R#
P_t=[]
for vv in V_t:              
    P_t.append(vv**2/R)
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'RMS value of voltage = %0.2f volts'%V_rms
print 'average power = %0.2f watts'%P_avg
subplot(211)
plot([tt*10**3 for tt in t],V_t)#
title('voltage vs time')
xlabel('time in ms')
ylabel('voltage in volts')      #ms-milli seconds(10**-3)
subplot(212)
plot([tt*10**3 for tt in t],P_t)
title('power vs time')
xlabel('time in ms')
ylabel('power in watts')      #ms-milli seconds(10**-3)
show()
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
RMS value of voltage = 70.71 volts
average power = 100.00 watts

Pg: 182 Ex:5.2

In [2]:
from __future__ import division
from numpy import arange,cos,pi,sqrt
%matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show
from sympy.mpmath import quad


#plot of V and t(already given with the question but to get clarity we plot it)
t_1=arange(0,1+0.001,0.001)
t_2=arange(1.001,2+0.001,0.001)
t=[]
for tt in t_1:
    t.append(tt)
for tt in t_2:
    t.append(tt)    
V_1=[];V_2=[]
for tt in t_1:
    V_1.append(3*tt)
for tt in t_2:
    V_2.append(6-3*tt)
V=[]
for vv in V_1:
    V.append(vv)
for vv in V_2:
    V.append(vv)    
plot(t,V)
title('voltage vs time')
xlabel('time in seconds')
ylabel('voltage in volts')
show()

#now find V_rms
T=2#      #from the plot of V vs t
V_rms=sqrt((1/T)*((quad(lambda t:(3*t)**2,[0,1]))+(quad(lambda t:(6-3*t)**2,[1,2]))))
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'RMS value = %0.2f volts'%V_rms
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
RMS value = 1.73 volts

Pg: 183 Ex:5.3

In [3]:
from __future__ import division
from math import pi,sqrt,sin,cos,atan
#V_1 and V_2 are phasors of given voltages
theta_1=-pi/4#      #for V_1
theta_2=-pi/6#      #for V_2 (in cos form)
V_1=complex(20*cos(theta_1),20*sin(theta_1))#
V_2=complex(10*cos(theta_2),10*sin(theta_2))#
V_s=V_1+V_2#
V=sqrt(((V_s.real)**2)+((V_s.imag)**2))#      #peak voltage of resultant summation
phi=atan((V_s.imag)/(V_s.real))#      #phase angle of resultant sum voltage
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'Peak value of resultant voltage = %0.2f volts'%V
print 'phase of resulting voltage = %0.2f degrees'%(phi*180/pi)      #converting phi in radians to degrees
#result : V_t=Vcos(wt+phi)
 All the values in the textbook are approximated hence the values in this code differ from those of Textbook
Peak value of resultant voltage = 29.77 volts
phase of resulting voltage = -40.01 degrees

Pg: 184 Ex:5.4

In [4]:
from __future__ import division
from math import pi,sqrt,sin,cos,atan
L=0.3#
C=40*10**-6#
R=100#
V_s_max=100#      #peak value of given voltage
W=500#      #angular frequency
V_s_phi=pi/6#      #phase angle in degrees
V_s=complex(V_s_max*cos(V_s_phi),V_s_max*sin(V_s_phi))#      #phasor for voltage source
Z_L=1J*W*L#      #complex impedance of inductance
Z_C=-1J/(W*C)#      #complex impedance of capacitance
Z_eq=R+Z_L+Z_C#      #R,Z_L and Z_C in series
I=V_s/Z_eq#      #phasor current
V_R=R*I#
V_L=Z_L*I#
V_C=Z_C*I#
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
#for resistance R
print 'For resistance R'
V_R_max=sqrt(((V_R.real)**2)+((V_R.imag)**2))
V_R_phi=(atan((V_R.imag)/(V_R.real)))*180/pi#
print 'peak value of voltage = %0.2f volts'%V_R_max
print 'phase angle = %0.2f degrees'%V_R_phi
#result : V_R=Vcos(wt+phi)  V-peak voltage
#for inductance L
print 'For inductance L'
V_L_max=sqrt(((V_L.real)**2)+((V_L.imag)**2))#
V_L_phi=(atan((V_L.imag)/(V_L.real)))*180/pi#
print 'peak value of voltage = %0.2f volts'%V_L_max
print 'phase angle = %0.2f degrees'%V_L_phi
#result : V_L=Vcos(wt+phi)  V-peak voltage
#for capacitor C
print 'For capacitor C'
V_C_max=sqrt(((V_C.real)**2)+((V_C.imag)**2))#
V_C_phi=(atan((V_C.imag)/(V_C.real)))*180/pi#
print 'peak value of voltage = %0.2f volts'%V_C_max
print 'phase angle = %0.2f degrees'%V_C_phi      #cos(t)=cos(t-180)  (we get 75 instead of -105 given in textbook)
#result : V_C=Vcos(wt+phi)  V-peak voltage
print 'The phasor diagram cannot be plotted'
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
For resistance R
peak value of voltage = 70.71 volts
phase angle = -15.00 degrees
For inductance L
peak value of voltage = 106.07 volts
phase angle = 75.00 degrees
For capacitor C
peak value of voltage = 35.36 volts
phase angle = 75.00 degrees
The phasor diagram cannot be plotted

Pg: 185 Ex: 5.5

In [5]:
from __future__ import division
from math import pi,sqrt,sin,cos,atan
V_s_max=10#      #peak value of source voltage
phi=-pi/2#      #phase of source voltage
V_s=complex(10*cos(pi/2),10*sin(pi/2))#      #phasor of source voltage
W=1000#      #angular frequency
R=100#
L=0.1#
C=10*10**-6#
Z_L=1J*W*L#      #impedance of inductance
Z_C=-1J/(W*C)#      #impedance of capacitance
Z_RC=1/((1/R)+(1/Z_C))#      #R and Z_C in parallel combination
V_C=V_s*Z_RC/(Z_L+Z_RC)#      #voltage division principle
I=V_s/(Z_L+Z_RC)#      #current through source and inductor
I_R=V_C/R#      #current through resistance
I_C=V_C/Z_C#      #current through capacitor
#cos(t)=cos(180-t)
print 'peak value of Vc = %0.2f volts'%(sqrt(((V_C.real)**2)+((V_C.imag)**2)),)
print 'phase angle of Vc = %0.f degrees'%((atan((V_C.imag)/(V_C.real)))*180/pi)
##result : V_C=Vcos(wt+phi)  V-peak voltage
print 'current through source and inductor =',I,'amperes'
print 'current through resistance = ',I_R,'amperes'
print 'current through capacitance = ',I_C,'amperes'
peak value of Vc = 10.00 volts
phase angle of Vc = 0 degrees
current through source and inductor = (0.1+0.1j) amperes
current through resistance =  (0.1+0j) amperes
current through capacitance =  (-0+0.1j) amperes

Pg: 187 Ex:5.6

In [6]:
from __future__ import division
from math import pi,sqrt,sin,cos,atan
from numpy import mat

V_s_max=2#      #peak value of source voltage
V_s_phi=-pi/2#      #phase angle of source voltage
V_s=complex(V_s_max*cos(V_s_phi),V_s_max*sin(V_s_phi))#
R=10#
Z_C=-1J*5#      #impedance of capacitance
Z_L=1J*10#      #impedance of inductance
I_s_max=1.5#      #peak value of current source
I_s_phi=0#      #phase angle of current source
I_s=complex(I_s_max*cos(I_s_phi),I_s_max*sin(I_s_phi))#
#we write the standard equations of V_1 and V_2 in matrix form
#from node-voltage relation
A=[[0.1+1J*0.2,-1J*0.2],[-1J*0.2,1J*0.1]]      #coefficient matrix
B=[[-1J*2],[1.5]]#      #constant matrix
#As in A*X=B form
A=mat(A);B=mat(B)
V=(A**-1)*B#
V_1=sqrt(((V[0,0].real))**2+((V[0,0].imag))**2)#      #peak value of V_1
V_1_phi=atan((V[0,0].imag)/(V[0,0].real))#      #phase angle of V_1
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'peak value of V1 = %0.2f volts'%V_1
print 'phase angle of V1 = %0.2f degrees'%(V_1_phi*180/pi)
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
peak value of V1 = 16.12 volts
phase angle of V1 = 29.74 degrees

Pg: 188 Ex:5.7

In [7]:
from __future__ import division
from math import pi,sqrt,sin,cos,atan
from numpy import mat,conj

phi_v=-pi/2#      #angle of voltage source
phi_i=-3*pi/4#      #angle of current source
phi=phi_v-phi_i#      #power angle
V_s_max=10#      #peak value of voltage source
V_s_phi=phi_v#      #phase angle of voltage source
R=100#
V_s=complex(V_s_max*cos(V_s_phi),V_s_max*sin(V_s_phi))#      #phasor of voltage source
X_L=1J*100#
X_C=-1J*100#
I_max=0.1414#      #peak value of current
I_phi=phi_i#      #phase angle of current
I=complex(I_max*cos(I_phi),I_max*sin(I_phi))#      #phasor of current
V_s_rms=V_s_max/sqrt(2)#      #rms value of voltage
I_rms=I_max/sqrt(2)#      #rms value of current
I_R_max=0.1#      #peak value
I_R_phi=-2*pi#      #phase angle
I_R=complex(I_R_max*cos(I_R_phi),I_R_max*sin(I_R_phi))#      #phasor of current
I_R_rms=I_R_max/sqrt(2)#      #rms value
I_C_max=0.1#      #peak value
I_C_phi=-pi/2#      #phase angle
I_C=complex(I_C_max*cos(I_C_phi),I_C_max*sin(I_C_phi))#      #phasor current in capacitor
I_C_rms=I_C_max/sqrt(2)#      #rms value
P=V_s_rms*I_rms*cos(phi)#      #power by source
Q=V_s_rms*I_rms*sin(phi)#      #reactive power by source
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'power delivered by source = %0.2f watts'%P
print 'reactive power delivered by source = %0.2f VARs'%Q
#using complex power method
print 'Using complex power method:'


S=(1/2)*V_s*conj(I)#      #complex power
P=(S.real)#
Q=(S.imag)#
print 'power delivered by source = %0.2f watts'%P
print 'reactive power delivered by source = %0.2f VARs'%Q
print 'we see that, in both the methods answers are the same'
Q_L=I_rms**2*X_L/1J#      #reactive power to inductance
Q_C=I_C_rms**2*X_C/1J#      #reactive power to capacitance
P_R=I_R_rms**2*R#      #power to resistance
print 'reactive power delivered to inductance = %0.2f VARs'%abs(Q_L)
print 'reactive power delivered to capacitance = %0.2f VARs'%abs(Q_C)
print 'power delivered to resistance = %0.2f watts'%P_R
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
power delivered by source = 0.50 watts
reactive power delivered by source = 0.50 VARs
Using complex power method:
power delivered by source = 0.50 watts
reactive power delivered by source = 0.50 VARs
we see that, in both the methods answers are the same
reactive power delivered to inductance = 1.00 VARs
reactive power delivered to capacitance = 0.50 VARs
power delivered to resistance = 0.50 watts

Pg: 189 Ex:5.8

In [8]:
from __future__ import division
from math import degrees,pi,sqrt,acos,tan,atan,cos
Vrms = 10**2 #V
Irms= 10**2 #amp
pf= 0.5
pf1= 0.7
r= 1.41
#CALCULATIONS
PA= Vrms*Irms*pf
QA= -sqrt((Vrms*Irms)**2-PA**2)/1000
a= acos(pf1)*180/pi
QB= PA*tan(pi/180*a)/1000
P= 2*PA/1000
Q= QA+QB
o= atan(Q/P)
pf2= cos(o)
A= degrees(o)+69.18
S= sqrt(P**2+Q**2)
I= S*r
#RESULTS
print 'Phasor Current = %.3f A'%I
print '\n Angle = %.2f degrees'%A
Phasor Current = 14.966 A

 Angle = 49.59 degrees

Pg: 190 Ex: 5.9

In [9]:
from __future__ import division
from math import degrees,pi,sqrt,acos,tan,atan,cos
#L is load
P_L=50*10**3#      #power of load
f=60#      #frequency
V_rms=10*10**3#      #rms voltage
PF_L=0.6#      #power factor
phi_L=acos(PF_L)#      #power angle
Q_L=P_L*tan(phi_L)#      #reactive power of load
#when capacitor is added, power angle changes
PF_L_new=0.9#
phi_L_new=acos(PF_L_new)#
Q_new=P_L*tan(phi_L_new)#
Q_C=Q_new-Q_L#      #reactive power of capacitance
X_C=-V_rms**2/Q_C#      #reactance of capacitor
W=2*pi*f#      #angular frequency
C=1/(W*abs(X_C))#      #capacitance
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'Required capacitance = %0.2f micro-farads'%(C*10**6)
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
Required capacitance = 1.13 micro-farads

Pg: 191 Ex: 5.10

In [10]:
from __future__ import division
from math import degrees,pi,sqrt,acos,tan,atan,cos
R=100#
V_s_max=100#      #peak value of voltage
V_s_phi=0#      #phase angle of voltage
V_s=complex(V_s_max*cos(V_s_phi),V_s_max*sin(V_s_phi))#      #phasor of voltage
Z_C=-1J*100#      #impedance of capacitance
I_s_max=1#      #peak value of current
I_s_phi=pi/2#      #phase angle of current
I_s=complex(I_s_max*cos(I_s_phi),I_s_max*sin(I_s_phi))#      #phasor of current
#zeroing sources to find Z_t i.e., thevenin impedance
Z_t=1/((1/R)+(1/Z_C))#      #R and Z_C are in parallel combination
#apply short-circuit to find I_sc i.e., short-circuit current
I_R=abs(V_s)/R#      #ohm's law
I_sc=I_R-I_s#      #applying KCL
V_t=I_sc*Z_t#      #thevenin voltage
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'FOR THEVENIN CIRCUIT:'
print 'thevenin voltage'
print 'peak value of voltage = %0.2f volts'%abs(V_t)
#cos(t)=cos(t-180)
print atan((V_t.imag)/(V_t.real))*180/pi,'phase angle in degrees'
print 'thevenin resistance'
print 'peak value of resistance = %0.2f ohms'%abs(Z_t)
print 'phase angle = %0.2f degrees'%(atan((Z_t.imag)/(Z_t.real))*180/pi)
print 'FOR NORTON CIRCUIT:'
print 'norton current'
print 'peak value of norton current = %0.2f amperes'%(abs(I_sc))
print 'phase angle = %0.2f degrees'%(atan((I_sc.imag)/(I_sc.real))*180/pi)
print 'resistance'
print 'peak value of resistance = %0.2f ohms'%abs(Z_t)
print 'phase angle = %0.2f degrees'%(atan((Z_t.imag)/(Z_t.real))*180/pi)
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
FOR THEVENIN CIRCUIT:
thevenin voltage
peak value of voltage = 100.00 volts
90.0 phase angle in degrees
thevenin resistance
peak value of resistance = 70.71 ohms
phase angle = -45.00 degrees
FOR NORTON CIRCUIT:
norton current
peak value of norton current = 1.41 amperes
phase angle = -45.00 degrees
resistance
peak value of resistance = 70.71 ohms
phase angle = -45.00 degrees

Pg: 192 Ex: 5.11

In [11]:
from __future__ import division
from math import degrees,pi,sqrt,acos,tan,atan,cos
from numpy import conj
#thevenin voltage
V_t_max=100#
V_t_phi=-pi/2#
V_t=complex(V_t_max*cos(V_t_phi),V_t_max*sin(V_t_phi))#
#thevenin resistance
Z_t_max=70.71#
Z_t_phi=-pi/4#
Z_t=complex(Z_t_max*cos(Z_t_phi),Z_t_max*sin(Z_t_phi))#
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
#a) Any complex load
print 'FOR ANY COMPLEX LOAD'
Z_load=conj(Z_t)#
I_a=V_t/(Z_t+Z_load)#      #ohm's law
I_a_rms=I_a/sqrt(2)#      #rms value
P_1=abs(I_a_rms)**2*(Z_load.real)#      #power
print 'required complex load impedance : {0:0.2f}+j*{0:0.2f}'.format(Z_load.real,Z_load.imag)
print 'power delivered to load = %0.2f watts'%P_1
#b) purely resistive load
print 'FOR PURE RESISTIVE LOAD'
R_load=abs(Z_t)#
I_b=V_t/(Z_t+R_load)#
I_b_rms=I_b/sqrt(2)#
P_2=abs(I_b_rms)**2*R_load#
print 'required pure resistive load : ',R_load
print 'power delivered to load:  %0.2f'%P_2
 All the values in the textbook are approximated hence the values in this code differ from those of Textbook
FOR ANY COMPLEX LOAD
required complex load impedance : 50.00+j*50.00
power delivered to load = 25.00 watts
FOR PURE RESISTIVE LOAD
required pure resistive load :  70.71
power delivered to load:  20.71

Pg: 193 Ex: 5.12

In [12]:
from __future__ import division
from math import degrees,pi,sqrt,acos,tan,atan,cos
V_Y=1000#      #line to neutral voltage
f=60#      #frequency
L=0.1#      #inductance
R=50#
W=2*pi*f#      #angular frequency
Z=complex(R,W*L)#      #complex impedance
phi=atan((Z.imag)/(Z.real))#
#Balanced wye-wye calculations
V_an=complex(1000*cos(0),1000*sin(0))#
V_bn=complex(1000*cos(-2*pi/3),1000*sin(-2*pi/3))#
V_cn=complex(1000*cos(2*pi/3),1000*sin(2*pi/3))#
I_aA=V_an/Z#
I_bB=V_bn/Z#
I_cC=V_cn/Z#
#line-line phasors
V_ab=V_an*sqrt(3)*complex(cos(pi/6),sin(pi/6))#
V_bc=V_bn*sqrt(3)*complex(cos(pi/6),sin(pi/6))#
V_ca=V_cn*sqrt(3)*complex(cos(pi/6),sin(pi/6))#
I_L=abs(I_aA)#
P=(3/2)*V_Y*I_L*cos(phi)#      #power
Q=(3/2)*V_Y*I_L*sin(phi)#      #reactive power
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'LINE CURRENTS'
print 'IaA= {0:0.3f}+j*{1:0.3f}'.format(I_aA.real,I_aA.imag)
print 'IbB= {0:0.3f}+j*{1:0.3f}'.format(I_bB.real,I_bB.imag)
print 'IcC= {0:0.3f}+j*{1:0.3f}'.format(I_cC.real,I_cC.imag)
print 'LINE-LINE VOLTAGES'
print 'Vab= {0:0.3f}+j*{1:0.3f}'.format(V_ab.real,V_ab.imag)
print 'Vbc= {0:0.3f}+j*{1:0.3f}'.format(V_bc.real,V_bc.imag)
print 'Vca= {0:0.3f}+j*{1:0.3f}'.format(V_ca.real,V_ca.imag)
print 'POWER = %0.2f WATTS'%P
print 'REACTIVE POWER = %0.2f VARs'%Q
print 'the phasor diagram cannot be plotted'
 All the values in the textbook are approximated hence the values in this code differ from those of Textbook
LINE CURRENTS
IaA= 12.751+j*-9.614
IbB= -14.702+j*-6.236
IcC= 1.951+j*15.850
LINE-LINE VOLTAGES
Vab= 1500.000+j*866.025
Vbc= 0.000+j*-1732.051
Vca= -1500.000+j*866.025
POWER = 19126.69 WATTS
REACTIVE POWER = 14421.18 VARs
the phasor diagram cannot be plotted

Pg: 194 Ex: 5.13

In [13]:
from __future__ import division
from math import degrees,pi,sqrt,acos,tan,atan,cos

Z_line=complex(0.3,0.4)#      #impedance of wire
Z_d=complex(30,6)#      #load impedance
R=(Z_d.real)#
R_line=(Z_line.real)#
#source voltages
V_ab=complex(1000*cos(pi/6),1000*sin(pi/6))#
V_bc=complex(1000*cos(-pi/2),1000*sin(-pi/2))#
V_ca=complex(1000*cos(5*pi/6),1000*sin(5*pi/6))#
#choosing A phase of wye-equivalent circuit
V_an=V_ab/(sqrt(3)*complex(cos(pi/6),sin(pi/6)))#
Z_Y=Z_d/3#
I_aA=V_an/(Z_line+Z_Y)#      #line current
I_aA_rms=abs(I_aA)/sqrt(2)#
V_An=I_aA*Z_Y#      #line to neutral voltage
V_AB=V_An*sqrt(3)*complex(cos(pi/6),sin(pi/6))#      #line to line voltage at the load
I_AB=V_AB/Z_d#      #current through phase AB
I_AB_rms=abs(I_AB)/sqrt(2)#      #rms value
P_AB=I_AB_rms**2*R#      #power delivered to phase AB
#power delivered in other two phases is same
P=3*P_AB#      #total power
P_A=I_aA_rms**2*R_line#      #power lost in line A
#power lost in other two lines is same
P_line=3*P_A#
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
IbB= I_aA*complex(cos(-2*pi/3),sin(-2*pi/3))
IcC= I_aA*complex(cos(2*pi/3),sin(2*pi/3))
print 'LINE CURRENTS'
print 'IaA= {0:0.3f}+j*{1:0.3f}'.format(I_aA.real,I_aA.imag)
print 'IbB= {0:0.3f}+j*{1:0.3f}'.format(I_bB.real,I_bB.imag)
print 'IcC= {0:0.3f}+j*{1:0.3f}'.format(I_cC.real,I_cC.imag)
VBB=V_AB*complex(cos(-2*pi/3),sin(-2*pi/3)),'VBB='
VCC=V_AB*complex(cos(2*pi/3),sin(2*pi/3)),'VCC='

print 'LINE-LINE VOLTAGES'
print 'VAB= {0:0.3f}+j*{1:0.3f}'.format(V_ab.real,V_ab.imag)
print 'VBC= {0:0.3f}+j*{1:0.3f}'.format(V_bc.real,V_bc.imag)
print 'VCA= {0:0.3f}+j*{1:0.3f}'.format(V_ca.real,V_ca.imag)

print 'power delivered to load = %0.2f watts'%P
print 'total power dissipated in the line = %0.2f VArs'%P_line
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
LINE CURRENTS
IaA= 53.167+j*-12.388
IbB= -14.702+j*-6.236
IcC= 1.951+j*15.850
LINE-LINE VOLTAGES
VAB= 866.025+j*500.000
VBC= 0.000+j*-1000.000
VCA= -866.025+j*500.000
power delivered to load = 44702.73 watts
total power dissipated in the line = 1341.08 VArs

Pg: 194 Ex: 5.14

In [14]:
from numpy import mat,conj
from __future__ import division
from math import sqrt,pi,sin,cos
V_1=10**3*2.2*sqrt(2)*complex(cos(0),sin(0))#
V_2=10**3*2*sqrt(2)*complex(cos(-pi/18),sin(-pi/18))#
#writing matrix form of mesh current equaions obtained by KVL
Z=[[5+3*1J+50*complex(cos(-pi/18),sin(-pi/18)),-50*complex(cos(-pi/18),sin(-pi/18))],[-50*complex(cos(-pi/18),sin(-pi/18)),4+1J+50*complex(cos(-pi/18),sin(-pi/18))]]      #coefficient matrix
V=[[2200*sqrt(2)],[-2000*sqrt(2)*complex(cos(-pi/18),sin(-pi/18))]]#      #voltage matrix
Z=mat(Z);V=mat(V)
I=Z/V#      #current matrix
S_1=(1/2)*V_1*conj((I[0,0]))#      #complex power
P_1=(S_1.real)#      #power
Q_1=(S_1.imag)#      #reactive power
print "All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'real power supplied by V1 = %0.2f watts'%P_1
print 'reactive power supplied by V1 = %0.2f VARs'%Q_1
All the values in the textbook are approximated hence the values in this code differ from those of Textbook
real power supplied by V1 = 27.12 watts
reactive power supplied by V1 = 2.84 VARs