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 $5\,$mH. Calculate the capacitance that needs to be connected in parallel with the resistive load to ensure that the power delivered to the load is $500\,$W. (Note that there are two possible capacitance values; choose the value that gives a smaller source current.)

(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_6_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_6_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_6_orig.in and produces a new circuit file phasor_6.in, after replacing \$C with the value of our choice.

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

The circuit file (phasor_6.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on phasor_6.in) creates data files phasor_6_1.dat and phasor_6_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_6.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_6_1.dat
phasors in rectangular form:
IR: (   9.23,   -6.15)
IC: (   3.08,    4.62)
Is: (  12.31,   -1.54)
Vs: ( 100.00,    0.00)
phasors in polar form:
IR: magnitude:   11.09, angle:  -33.69 deg
IC: magnitude:    5.55, angle:   56.31 deg
Is: magnitude:   12.40, angle:   -7.12 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_6.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_6_2.dat
phasors in rectangular form:
SR: ( 615.38,    0.00)
SL: (   0.00,  384.60)
SC: (   0.00, -307.68)
SVs: ( 615.38,   76.92)
phasors in polar form:
SR: magnitude:  615.38, angle:    0.00 deg
SL: magnitude:  384.60, angle:   90.00 deg
SC: magnitude:  307.68, angle:  -90.00 deg
SVs: magnitude:  620.17, angle:    7.12 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 [ ]: