Phasors
A series $RLC$ circuit is driven by an AC voltage source $V_s(t) = 325\,\sin\,(100\,\pi\,t)$. With $R = 10\,\Omega$ and $L = 100\,$mH, determine the value of the capacitance $C$ for which the voltage phasors across the capacitor and inductor are equal in magnitude. Find the angle between the two phasors.(Follow the convention that $\cos\,(\omega \,t)$ corresponds to the phasor $1\,\angle {0}$.)
from IPython.display import Image
Image(filename =r'phasor_1_fig_1.png', width=400)
# run this cell to view the circuit file.
%pycat phasor_1_orig.in
We now replace the string \$C with the value of our choice by running the python script given below. It takes an existing circuit file phasor_1_orig.in and produces a new circuit file phasor_1.in, after replacing \$C with the value of our choice.
import gseim_calc as calc
s_C = '200e-6' # to be changed by user
l = [
('$C', s_C),
]
calc.replace_strings_1("phasor_1_orig.in", "phasor_1.in", l)
print('phasor_1.in is ready for execution')
phasor_1.in is ready for execution
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("phasor_1.in")
os.system('run_gseim phasor_1.in')
Circuit: filename = phasor_1.in main: i_solve = 0 GSEIM: Program completed.
0
The circuit file (phasor_1.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on phasor_1.in) creates data files phasor_1_1.dat and phasor_1_2.dat in the same directory. We can now use the python code below to compute and display the quantities of interest.
import numpy as np
import gseim_calc as calc
import os
import sys
import dos_unix
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from setsize import set_size
rad_to_deg = 180.0/np.pi
slv = calc.slv("phasor_1.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
VR = slv.get_scalar_complex_1(i_slv, i_out, "VR_ac", u)
VC = slv.get_scalar_complex_1(i_slv, i_out, "VC_ac", u)
VL = slv.get_scalar_complex_1(i_slv, i_out, "VL_ac", u)
Vs = slv.get_scalar_complex_1(i_slv, i_out, "Vs_ac", u)
IR = slv.get_scalar_complex_1(i_slv, i_out, "IR_ac", u)
s_format = "%7.2f"
print('phasors in rectangular form:')
calc.print_complex_rect('VR', VR, s_format)
calc.print_complex_rect('VL', VL, s_format)
calc.print_complex_rect('VC', VC, s_format)
calc.print_complex_rect('Vs', Vs, s_format)
calc.print_complex_rect('IR', IR, s_format)
print('phasors in polar form:')
calc.print_complex_polar('VR', VR, s_format)
calc.print_complex_polar('VL', VL, s_format)
calc.print_complex_polar('VC', VC, s_format)
calc.print_complex_polar('Vs', Vs, s_format)
calc.print_complex_polar('IR', IR, s_format)
phi_L = np.angle(VL)*rad_to_deg
phi_C = np.angle(VC)*rad_to_deg
print('phi_L: %6.1f'%phi_L)
print('phi_C: %6.1f'%phi_C)
print('phi_L-phi_C: %6.1f'%(phi_L-phi_C))
l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]
l1 = []
l1_labels = []
color_VR = calc.phasor_append_1a(l1, l1_labels, VR, "$V_R$", l_colors)
color_VL = calc.phasor_append_1a(l1, l1_labels, VL, "$V_L$", l_colors)
color_VC = calc.phasor_append_1a(l1, l1_labels, VC, "$V_C$", l_colors)
color_Vs = calc.phasor_append_1a(l1, l1_labels, Vs, "$V_s$", l_colors)
color_IR = calc.phasor_append_1a(l1, l1_labels, IR, "$I_R$", l_colors)
theta_deg = 20.0
length_arrow = calc.phasor_3(l1, 0.02)
l1_arrow = calc.phasor_2(l1, theta_deg, length_arrow, 0.2)
l2 = []
l2_colors = []
calc.phasor_append_2(l2, l2_colors, VC, (VR + VC), color_VR)
calc.phasor_append_2(l2, l2_colors, (VR + VC), (VR + VC + VL), color_VL)
l2_arrow = calc.phasor_2(l2, theta_deg, length_arrow, 0.2)
fig, ax = plt.subplots()
ax.set_aspect('equal', adjustable='box')
ax.grid()
for i, l_dummy in enumerate(l1_arrow):
for k, t in enumerate(l_dummy):
if (k == 0):
ax.plot(t[0],t[1], color=l_colors[i], label=l1_labels[i])
else:
ax.plot(t[0],t[1], color=l_colors[i])
for i, l_dummy in enumerate(l2_arrow):
for k, t in enumerate(l_dummy):
ax.plot(t[0],t[1], color=l2_colors[i], linestyle='--', dashes=(4, 2))
calc.revise_axis_limits_1(ax, 3.0)
ax.legend(loc='center left', fontsize=11, bbox_to_anchor=(1.05, 0.5))
plt.xlabel('Re (V)', fontsize=11)
plt.ylabel('Im (V)', fontsize=11)
plt.show()
filename: phasor_1_1.dat phasors in rectangular form: VR: (-148.05, -95.51) VL: ( 300.07, -465.12) VC: (-152.02, 235.63) Vs: ( 0.00, -325.00) IR: ( -14.81, -9.55) phasors in polar form: VR: magnitude: 176.19, angle: -147.17 deg VL: magnitude: 553.51, angle: -57.17 deg VC: magnitude: 280.41, angle: 122.83 deg Vs: magnitude: 325.00, angle: -90.00 deg IR: magnitude: 17.62, angle: -147.17 deg phi_L: -57.2 phi_C: 122.8 phi_L-phi_C: -180.0
import numpy as np
import gseim_calc as calc
import os
import sys
import dos_unix
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from setsize import set_size
rad_to_deg = 180.0/np.pi
slv = calc.slv("phasor_1.in")
i_slv = 0
i_out = 1
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
SR = slv.get_scalar_complex_1(i_slv, i_out, "S_R", u)
SC = slv.get_scalar_complex_1(i_slv, i_out, "S_L", u)
SL = slv.get_scalar_complex_1(i_slv, i_out, "S_C", u)
SVs = slv.get_scalar_complex_1(i_slv, i_out, "S_Vs", u)
s_format = "%7.2f"
print('phasors in rectangular form:')
calc.print_complex_rect('SR', SR, s_format)
calc.print_complex_rect('SL', SL, s_format)
calc.print_complex_rect('SC', SC, s_format)
calc.print_complex_rect('SVs', SVs, s_format)
print('phasors in polar form:')
calc.print_complex_polar('SR', SR, s_format)
calc.print_complex_polar('SL', SL, s_format)
calc.print_complex_polar('SC', SC, s_format)
calc.print_complex_polar('SVs', SVs, s_format)
l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]
l1 = []
l1_labels = []
color_SR = calc.phasor_append_1a(l1, l1_labels, SR, "$S_R$", l_colors)
color_SL = calc.phasor_append_1a(l1, l1_labels, SL, "$S_L$", l_colors)
color_SC = calc.phasor_append_1a(l1, l1_labels, SC, "$S_C$", l_colors)
color_SVs = calc.phasor_append_1a(l1, l1_labels, SVs, "$S_{Vs}$", l_colors)
theta_deg = 20.0
length_arrow = calc.phasor_3(l1, 0.02)
l1_arrow = calc.phasor_2(l1, theta_deg, length_arrow, 0.2)
l2 = []
l2_colors = []
calc.phasor_append_2(l2, l2_colors, SC, (SR + SC), color_SR)
calc.phasor_append_2(l2, l2_colors, (SR + SC), (SR + SC + SL), color_SL)
l2_arrow = calc.phasor_2(l2, theta_deg, length_arrow, 0.2)
fig, ax = plt.subplots()
ax.set_aspect('equal', adjustable='box')
ax.grid()
for i, l_dummy in enumerate(l1_arrow):
for k, t in enumerate(l_dummy):
if (k == 0):
ax.plot(t[0],t[1], color=l_colors[i], label=l1_labels[i])
else:
ax.plot(t[0],t[1], color=l_colors[i])
for i, l_dummy in enumerate(l2_arrow):
for k, t in enumerate(l_dummy):
ax.plot(t[0],t[1], color=l2_colors[i], linestyle='--', dashes=(4, 2))
calc.revise_axis_limits_1(ax, 3.0)
ax.legend(loc='center left', fontsize=11, bbox_to_anchor=(1.05, 0.5))
plt.xlabel('Re (S)', fontsize=11)
plt.ylabel('Im (S)', fontsize=11)
plt.show()
filename: phasor_1_2.dat phasors in rectangular form: SR: (1552.11, -0.00) SL: ( 0.00, -2470.25) SC: ( 0.00, 4876.09) SVs: (1552.11, 2405.83) phasors in polar form: SR: magnitude: 1552.11, angle: -0.00 deg SL: magnitude: 2470.25, angle: -90.00 deg SC: magnitude: 4876.09, angle: 90.00 deg SVs: magnitude: 2863.05, angle: 57.17 deg
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.