from IPython.display import Image
Image(filename =r'dc_circuit_3_fig_1.png', width=180)
# run this cell to view the circuit file.
%pycat dc_circuit_3_orig.in
We now replace the string \$R2 with the value of our choice by running the python script given below. It takes an existing circuit file <TT>dc_circuit_3_orig.in</TT> and produces a new circuit file <TT>dc_circuit_3.in</TT>, after replacing \\$R2 with the value of our choice.
import gseim_calc as calc
s_R2 = '5' # to be changed by user
l = [
('$R2', s_R2),
]
calc.replace_strings_1("dc_circuit_3_orig.in", "dc_circuit_3.in", l)
print('dc_circuit_3.in is ready for execution')
dc_circuit_3.in is ready for execution
Execute the following cell to run GSEIM on dc_circuit_3.in.
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("dc_circuit_3.in")
os.system('run_gseim dc_circuit_3.in')
Circuit: filename = dc_circuit_3.in main: i_solve = 0 GSEIM: Program completed.
0
The circuit file (dc_circuit_3.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on dc_circuit_3.in) creates the data file dc_circuit_3.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 matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("dc_circuit_3.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
RL = slv.get_array_double(i_slv, i_out, 'RL', u)
PL = slv.get_array_double(i_slv, i_out, 'PL', u)
k_max = np.argmax(PL)
s_format = "%11.4E"
calc.print_double_1('RL (approx) for maximum power:', RL[k_max], s_format)
calc.print_double_1('maximum power:', PL[k_max], s_format)
color1='green'
fig, ax = plt.subplots()
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(4, 2.5, ax)
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax.plot(RL, PL, color=color1, linewidth=1.0, label="$P_L$")
plt.xlabel(r'$R_L\,(\Omega)$', fontsize=11)
plt.ylabel(r'$P_L\,$' + '(W)', fontsize=11)
plt.tight_layout()
plt.show()
filename: dc_circuit_3.dat RL (approx) for maximum power:: 3.0612E+00 maximum power:: 3.8942E+00
This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.