Phasors
The current delivered by the source in the circuit is $10\,\cos\,(120\,\pi\,t - 15^{\circ})$. Load impedance $Z_1$ consumes $300\,$W active power, and load $Z_2$ delivers $300\,$VAR reactive power.- Find $Z_1$ and $Z_2$.
- Calculate ${\bf{I}}_1$ and ${\bf{I}}_2$.
- Draw the phasor diagrams showing KCL.
In [1]:
from IPython.display import Image
Image(filename =r'phasor_7_fig_1.png', width=320)
Out[1]:
In [2]:
# RL circuit
# run this cell to view the circuit file.
%pycat phasor_7_orig.in
We now replace strings such as \$Z1_mag with the values of our choice by running the python script given below. It takes an existing circuit file phasor_7_orig.in and produces a new circuit file phasor_7.in, after replacing \$Z1_mag, etc, with the values of our choice.
In [3]:
import gseim_calc as calc
s_Z1_mag = '10' # to be changed by user
s_Z1_theta_deg = '40' # to be changed by user
s_Z2_mag = '20' # to be changed by user
s_Z2_theta_deg = '-30' # to be changed by user
l = [
('$Z1_mag', s_Z1_mag),
('$Z1_theta_deg', s_Z1_theta_deg),
('$Z2_mag', s_Z2_mag),
('$Z2_theta_deg', s_Z2_theta_deg),
]
calc.replace_strings_1("phasor_7_orig.in", "phasor_7.in", l)
print('phasor_7.in is ready for execution')
phasor_7.in is ready for execution
Execute the following cell to run GSEIM on phasor_7.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("phasor_7.in")
os.system('run_gseim phasor_7.in')
Circuit: filename = phasor_7.in main: i_solve = 0 GSEIM: Program completed.
Out[4]:
0
The last step (i.e., running GSEIM on phasor_7.in) creates the data file phasor_7.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 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_7.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
IZ1 = slv.get_scalar_complex_1(i_slv, i_out, "IZ1", u)
IZ2 = slv.get_scalar_complex_1(i_slv, i_out, "IZ2", u)
SZ1 = slv.get_scalar_complex_1(i_slv, i_out, "SZ1", u)
SZ2 = slv.get_scalar_complex_1(i_slv, i_out, "SZ2", u)
Is = slv.get_scalar_complex_1(i_slv, i_out, "Is", u)
Vs = slv.get_scalar_complex_1(i_slv, i_out, "Vs", u)
s_format = "%7.2f"
print('phasors in rectangular form:')
calc.print_complex_rect('IZ1', IZ1, s_format)
calc.print_complex_rect('IZ2', IZ2, s_format)
calc.print_complex_rect('SZ1', SZ1, s_format)
calc.print_complex_rect('SZ2', SZ2, s_format)
calc.print_complex_rect('Is', Is, s_format)
calc.print_complex_rect('Vs', Vs, s_format)
print('phasors in polar form:')
calc.print_complex_polar('IZ1', IZ1, s_format)
calc.print_complex_polar('IZ2', IZ2, s_format)
calc.print_complex_polar('SZ1', SZ1, s_format)
calc.print_complex_polar('SZ2', SZ2, s_format)
calc.print_complex_polar('Is', Is, s_format)
calc.print_complex_polar('Vs', Vs, s_format)
Vs1 = Vs/20.0
l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]
l1 = []
l1_labels = []
color_IZ1 = calc.phasor_append_1a(l1, l1_labels, IZ1, "$I_1$", l_colors)
color_IZ2 = calc.phasor_append_1a(l1, l1_labels, IZ2, "$I_2$", l_colors)
color_Is = calc.phasor_append_1a(l1, l1_labels, Is, "$I_s$", l_colors)
color_Vs1 = calc.phasor_append_1a(l1, l1_labels, Vs1, "$V_s/20$", 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, IZ1, (IZ1 + IZ2), color_IZ2)
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 (I)', fontsize=11)
plt.ylabel('Im (I)', fontsize=11)
plt.show()
filename: phasor_7.dat phasors in rectangular form: IZ1: ( 15.50, 1.36) IZ2: ( 2.01, 7.51) SZ1: ( 926.87, 777.74) SZ2: ( 523.92, -302.49) Is: ( 17.51, 8.87) Vs: ( 110.00, 110.00) phasors in polar form: IZ1: magnitude: 15.56, angle: 5.00 deg IZ2: magnitude: 7.78, angle: 75.00 deg SZ1: magnitude: 1209.95, angle: 40.00 deg SZ2: magnitude: 604.97, angle: -30.00 deg Is: magnitude: 19.63, angle: 26.86 deg Vs: magnitude: 155.56, angle: 45.00 deg
In [6]:
import numpy as np
import gseim_calc as calc
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_7.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
SZ1 = slv.get_scalar_complex_1(i_slv, i_out, "SZ1", u)
SZ2 = slv.get_scalar_complex_1(i_slv, i_out, "SZ2", u)
SVs = slv.get_scalar_complex_1(i_slv, i_out, "SVs", u)
s_format = "%7.2f"
print('phasors in rectangular form:')
calc.print_complex_rect('SZ1', SZ1, s_format)
calc.print_complex_rect('SZ2', SZ2, s_format)
calc.print_complex_rect('SVs', SVs, s_format)
print('phasors in polar form:')
calc.print_complex_polar('SZ1', SZ1, s_format)
calc.print_complex_polar('SZ2', SZ2, s_format)
calc.print_complex_polar('SVs', SVs, s_format)
l_colors = ["blue", "red", "green", "grey", "dodgerblue", "tomato"]
l1 = []
l1_labels = []
color_SZ1 = calc.phasor_append_1a(l1, l1_labels, SZ1, "$S_{Z1}$", l_colors)
color_SZ2 = calc.phasor_append_1a(l1, l1_labels, SZ2, "$S_{Z2}$", 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, SZ1, (SZ1 + SZ2), color_SZ2)
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_7.dat phasors in rectangular form: SZ1: ( 926.87, 777.74) SZ2: ( 523.92, -302.49) SVs: (1450.79, 475.25) phasors in polar form: SZ1: magnitude: 1209.95, angle: 40.00 deg SZ2: magnitude: 604.97, angle: -30.00 deg SVs: magnitude: 1526.65, angle: 18.14 deg
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.
In [ ]: