DC circuits
In the $V_o$ versus $V_i$ relationship for the diode circuit below, $V_{i1}=V_{o1}=3.2\,V$, $V_{i2}=8\,V$, $V_{o2}=5.72\,V$. The diode voltage is $0.7\,V$ in forward bias. Find $V_{CC}$ and $R_4$.In [1]:
from IPython.display import Image
Image(filename =r'dc_circuit_13_fig_1.png', width=550)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat dc_circuit_13_orig.in
We now replace strings \$R4 and \$Vcc with the value of our choice by running the python script given below. It takes an existing circuit file dc_circuit_13_orig.in and produces a new circuit file dc_circuit_13.in, after replacing \$R4 and \$Vcc with the values of our choice.
In [3]:
import gseim_calc as calc
s_Vcc = '10' # to be changed by user
s_R4 = '20k' # to be changed by user
l = [
('$Vcc', s_Vcc),
('$R4', s_R4),
]
calc.replace_strings_1("dc_circuit_13_orig.in", "dc_circuit_13.in", l)
print('dc_circuit_13.in is ready for execution')
dc_circuit_13.in is ready for execution
Execute the following cell to run GSEIM on dc_circuit_13.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("dc_circuit_13.in")
os.system('run_gseim dc_circuit_13.in')
Circuit: filename = dc_circuit_13.in GSEIM: Program completed.
Out[4]:
0
The circuit file (dc_circuit_13.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on dc_circuit_13.in) creates the data file, dc_circuit_13.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 matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("dc_circuit_13.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
Vi = slv.get_array_double(i_slv, i_out, "Vi", u)
Vo = slv.get_array_double(i_slv, i_out, "Vo", u)
Vi_given = 8.0
Vo_a = calc.get_value_1(Vi, Vo, Vi_given)
print('Vi2:', "%11.4E"%Vi_given, 'Vo:', "%11.4E"%Vo_a)
color1='red'
fig, ax = plt.subplots()
ax.set_aspect('equal', adjustable='box')
ax.grid()
ax.set_xlim(left=-4, right=10)
#set_size(6, 3, ax)
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax.plot(Vi, Vo, color=color1, linewidth=1.0, label="$V_o$")
plt.xlabel(r'$V_i$', fontsize=11)
plt.ylabel(r'$V_o$', fontsize=11)
plt.tight_layout()
plt.show()
filename: dc_circuit_13.dat Vi2: 8.0000E+00 Vo: 4.3705E+00
This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.
In [ ]: