DC circuits
In the circuit shown in the figure, the Thevenin resistance seen from $PQ$ is $144\,\Omega$.- Find $R_3$.
- Find $V_{Th}$ as seen from $PQ$.
- If a resistance $R_L=100\,\Omega$ is connected between $P$ and $Q$, what current will it draw?
In [1]:
from IPython.display import Image
Image(filename =r'dc_circuit_12_fig_1.png', width=250)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat dc_circuit_12_orig.in
We now replace the string \$R3 with the value of our choice by running the python script given below. It takes an existing circuit file dc_circuit_12_orig.in and produces a new circuit file dc_circuit_12.in, after replacing \$R3 with the value of our choice.
In [3]:
import gseim_calc as calc
s_R3 = '500' # to be changed by user
l = [
('$R3', s_R3),
]
calc.replace_strings_1("dc_circuit_12_orig.in", "dc_circuit_12.in", l)
print('dc_circuit_12.in is ready for execution')
dc_circuit_12.in is ready for execution
Execute the following cell to run GSEIM on dc_circuit_12.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("dc_circuit_12.in")
os.system('run_gseim dc_circuit_12.in')
Circuit: filename = dc_circuit_12.in main: i_solve = 0 @0 RL r 0.001 main: i_solve = 1 @0 RL r 1e+09 main: i_solve = 2 @0 RL r 100 GSEIM: Program completed.
Out[4]:
0
The circuit file (dc_circuit_12.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on dc_circuit_12.in) creates the data files dc_circuit_12_1.dat, etc. 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 matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("dc_circuit_12.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
VRL = slv.get_scalar_double(i_slv, i_out, "VRL", u)
IRL = slv.get_scalar_double(i_slv, i_out, "IRL", u)
Isc = IRL
i_slv = 1
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
VRL = slv.get_scalar_double(i_slv, i_out, "VRL", u)
IRL = slv.get_scalar_double(i_slv, i_out, "IRL", u)
Voc = VRL
RTh = Voc/Isc
i_slv = 2
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
VRL = slv.get_scalar_double(i_slv, i_out, "VRL", u)
IRL = slv.get_scalar_double(i_slv, i_out, "IRL", u)
s_format = "%11.4E"
calc.print_double_1('Isc', Isc, s_format)
calc.print_double_1('Voc', Voc, s_format)
calc.print_double_1('RTh', RTh, s_format)
calc.print_double_1('Current through RL for RL = 100 ohm', IRL, s_format)
filename: dc_circuit_12_1.dat filename: dc_circuit_12_2.dat filename: dc_circuit_12_3.dat Isc: 2.1132E-02 Voc: 3.5758E+00 RTh: 1.6921E+02 Current through RL for RL = 100 ohm: 1.3282E-02
This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.
In [ ]: