Time constants
In the circuit shown in the figure, the switch is closed for a long time and opens at $t=0$. The current $i$ is $3.5\,$A at $t=50\,$msec.- Find $i_L(0^-)$.
- Using $i_L(0^+)=i_L(0^-)$, find $i(0^+)$.
- Find $i(\infty)$.
- Let $i(t)=A\,e^{-t/\tau} + B$ for $t > 0$. Using $i(0^+)$ and $i(\infty)$, find $A$ and $B$.
- Obtain $\tau$ using the condition $i=3.5\,$A at $t=50\,$msec.
- From $\tau$, find $L$.
In [1]:
from IPython.display import Image
Image(filename =r'time_constant_5_fig_1.png', width=250)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat time_constant_5_orig.in
We now replace the string \$L with the value of our choice by running the python script given below. It takes an existing circuit file time_constant_5_orig.in and produces a new circuit file time_constant_5.in, after replacing \$L with the value of our choice.
In [3]:
import gseim_calc as calc
s_L = '0.4' # to be changed by user
l = [
('$L', s_L),
]
calc.replace_strings_1("time_constant_5_orig.in", "time_constant_5.in", l)
print('time_constant_5.in is ready for execution')
time_constant_5.in is ready for execution
Execute the following cell to run GSEIM on time_constant_5.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("time_constant_5.in")
os.system('run_gseim time_constant_5.in')
Circuit: filename = time_constant_5.in main: i_solve = 0 main: i_solve = 1 main: calling solve_trns Transient simulation starts... i=0 i=1000 i=2000 i=3000 i=4000 GSEIM: Program completed.
Out[4]:
0
The circuit file (time_constant_5.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on time_constant_5.in) creates the data file time_constant_5_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("time_constant_5.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
IR3_dc = slv.get_scalar_double(i_slv, i_out, 'IR3', u)
IL_dc = slv.get_scalar_double(i_slv, i_out, 'IL', u)
VL_dc = slv.get_scalar_double(i_slv, i_out, 'VL', u)
i_slv = 1
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t = u[:, 0]
t_end = t[-1]
IR30 = 3.5
IR3 = slv.get_array_double(i_slv, i_out, 'IR3', u)
IL = slv.get_array_double(i_slv, i_out, 'IL', u)
VL = slv.get_array_double(i_slv, i_out, 'VL', u)
ta = -20.0e-3
tb = 0.0
t_1 = np.array([ta, tb])
IR3_1 = np.array([IR3_dc, IR3_dc])
IL_1 = np.array([IL_dc, IL_dc])
VL_1 = np.array([VL_dc, VL_dc])
t_2 = np.concatenate((t_1, t))
IR3_2 = np.concatenate((IR3_1, IR3))
IL_2 = np.concatenate((IL_1, IL))
VL_2 = np.concatenate((VL_1, VL))
l_cross_1, l_cross_2 = calc.cross_over_points_1(t, IR3, 0.0, t_end, IR30)
print('time points at which i crosses', "%5.2f"%IR30, "A")
for t1 in l_cross_2:
print(" ", "%5.1f"%(t1*1e3), "msec")
color1='blue'
color2='green'
color3='red'
fig, ax = plt.subplots(3, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5.5, 6.0, ax[0])
for i in range(3):
ax[i].set_xlim(left=ta*1e3, right=t_end*1e3)
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
#ax[0].set_ylim(bottom=30.0, top=80.0)
#ax[2].set_ylim(bottom=2.0, top=10.0)
ax[0].set_ylabel(r'$i$ (A)', fontsize=12)
ax[1].set_ylabel(r'$i_L$ (A)', fontsize=12)
ax[2].set_ylabel(r'$V_L$ (V)', fontsize=12)
ax[0].tick_params(labelbottom=False)
ax[1].tick_params(labelbottom=False)
ax[0].plot(t_2*1e3, IR3_2, color=color1, linewidth=1.0, label="$i$")
ax[1].plot(t_2*1e3, IL_2, color=color1, linewidth=1.0, label="$i_L$")
ax[2].plot(t_2*1e3, VL_2, color=color2, linewidth=1.0, label="$V_L$")
ax[0].axhline(y = IR30, color = color3, linestyle = '--', linewidth=0.8, dashes=(5,5))
if len(l_cross_2) != 0:
ax[0].axvline(x = l_cross_2[0]*1e3, color = color3, linestyle = '--', linewidth=0.8, dashes=(5,5))
ax[2].set_xlabel('time (sec)', fontsize=11)
#plt.tight_layout()
plt.show()
filename: time_constant_5_1.dat
filename: time_constant_5_2.dat
time points at which i crosses 3.50 A
27.7 msec
This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.
In [ ]: