Phasors

A resistive load of $10\,\Omega$ is connected to an ac voltage source $V_s(t) = 100\,\cos\,(1000\,t)$ through an inductor of $10\,$mH. Calculate the capacitance that needs to be connected in parallel with the resistive load to ensure the power delivered to the load is $500\,$W.

(Follow the convention that $\cos\,(\omega \,t)$ corresponds to the phasor $1\,\angle {0}$.)

In [1]:
from IPython.display import Image
Image(filename =r'phasor_4_fig_1.png', width=350)
Out[1]:
No description has been provided for this image
In [2]:
# run this cell to view the circuit file.
%pycat phasor_4_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_4_orig.in and produces a new circuit file phasor_4.in, after replacing \$C with the value of our choice.

In [3]:
import gseim_calc as calc
s_C = '50e-6' # to be changed by user
l = [
  ('$C', s_C),
]
calc.replace_strings_1("phasor_4_orig.in", "phasor_4.in", l)
print('phasor_4.in is ready for execution')
phasor_4.in is ready for execution
Execute the following cell to run GSEIM on phasor_4.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("phasor_4.in")
os.system('run_gseim phasor_4.in')
Circuit: filename = phasor_4.in
main: i_solve = 0
GSEIM: Program completed.
Out[4]:
0

The circuit file (phasor_4.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on phasor_4.in) creates data files phasor_4_1.dat and phasor_4_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 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_4.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)
Is = slv.get_scalar_complex_1(i_slv, i_out, "Is_ac", u)
Vs = slv.get_scalar_complex_1(i_slv, i_out, "Vs_ac", u)

s_format = "%7.2f"

print('phasors in rectangular form:')

calc.print_complex_rect('IR', IR, s_format)
calc.print_complex_rect('IC', IC, 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('IR', IR, s_format)
calc.print_complex_polar('IC', IC, 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_IR  = calc.phasor_append_1a(l1, l1_labels, IR,  "$I_R$",    l_colors)
color_IC  = calc.phasor_append_1a(l1, l1_labels, IC,  "$I_C$",    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, IC, (IR + IC), color_IR)

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_4_1.dat
phasors in rectangular form:
IR: (   4.00,   -8.00)
IC: (   4.00,    2.00)
Is: (   8.00,   -6.00)
Vs: ( 100.00,    0.00)
phasors in polar form:
IR: magnitude:    8.94, angle:  -63.43 deg
IC: magnitude:    4.47, angle:   26.57 deg
Is: magnitude:   10.00, angle:  -36.87 deg
Vs: magnitude:  100.00, angle:    0.00 deg
No description has been provided for this image
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_4.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)
SL  = slv.get_scalar_complex_1(i_slv, i_out, "S_L",  u)
SC  = 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, SL, (SL + SR), color_SR)
calc.phasor_append_2(l2, l2_colors, (SL + SR), (SL + SR + SC), color_SC)

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_4_2.dat
phasors in rectangular form:
SR: ( 400.01,    0.00)
SL: (   0.00,  499.99)
SC: (   0.00, -200.00)
SVs: ( 400.01,  299.99)
phasors in polar form:
SR: magnitude:  400.01, angle:    0.00 deg
SL: magnitude:  499.99, angle:   90.00 deg
SC: magnitude:  200.00, angle:  -90.00 deg
SVs: magnitude:  500.00, angle:   36.87 deg
No description has been provided for this image

This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.

In [ ]: