Phasors
A parallel $RLC$ circuit is driven by an AC current source $I_s(t) = 100\,\sin\,(1000\,t)$. With $R = 10\,\Omega$, $L = 0.1\,$H, $C = 10\,\mu$F, determine- the phasor current through each component
- the phasor voltage across the current source
In [1]:
from IPython.display import Image
Image(filename =r'phasor_2_fig_1.png', width=370)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat phasor_2_orig.in
We now replace strings such as \$C with the values of our choice by running the python script given below. It takes an existing circuit file phasor_2_orig.in and produces a new circuit file phasor_2.in, after replacing \$C, etc with the values of our choice.
In [3]:
import gseim_calc as calc
s_R = '10'
s_L = '0.1'
s_C = '10e-6'
l = [
('$R', s_R),
('$L', s_L),
('$C', s_C),
]
calc.replace_strings_1("phasor_2_orig.in", "phasor_2.in", l)
print('phasor_2.in is ready for execution')
phasor_2.in is ready for execution
Execute the following cell to run GSEIM on phasor_2.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("phasor_2.in")
os.system('run_gseim phasor_2.in')
Circuit: filename = phasor_2.in main: i_solve = 0 GSEIM: Program completed.
Out[4]:
0
The circuit file (phasor_2.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on phasor_2.in) creates data files phasor_2_1.dat and phasor_2_2.dat in the same directory. We can now use the python code below to compute and display the quantities of interest.
In [5]:
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_2.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
IR = slv.get_scalar_complex_1(i_slv, i_out, "IR_ac", u)
IC = slv.get_scalar_complex_1(i_slv, i_out, "IC_ac", u)
IL = slv.get_scalar_complex_1(i_slv, i_out, "IL_ac", u)
IS = slv.get_scalar_complex_1(i_slv, i_out, "IS_ac", u)
VR = slv.get_scalar_complex_1(i_slv, i_out, "VR_ac", u)
s_format = "%7.2f"
print('phasors in rectangular form:')
calc.print_complex_rect('IR', IR, s_format)
calc.print_complex_rect('IL', IL, s_format)
calc.print_complex_rect('IC', IC, s_format)
calc.print_complex_rect('IS', IS, s_format)
calc.print_complex_rect('VR', IR, s_format)
print('phasors in polar form:')
calc.print_complex_polar('IR', IR, s_format)
calc.print_complex_polar('IL', IL, s_format)
calc.print_complex_polar('IC', IC, s_format)
calc.print_complex_polar('IS', IS, s_format)
calc.print_complex_polar('VR', IR, s_format)
filename: phasor_2_1.dat phasors in rectangular form: IR: ( 0.00, -100.00) IL: ( -10.00, -0.00) IC: ( 10.00, 0.00) IS: ( 0.00, 100.00) VR: ( 0.00, -100.00) phasors in polar form: IR: magnitude: 100.00, angle: -90.00 deg IL: magnitude: 10.00, angle: -180.00 deg IC: magnitude: 10.00, angle: 0.00 deg IS: magnitude: 100.00, angle: 90.00 deg VR: magnitude: 100.00, angle: -90.00 deg
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.
In [ ]: