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_1$ is $45\,$mA at $t=0.1\,$msec.
  1. Find $V_C(0^-)$.
  2. Using $V_C(0^+)=V_C(0^-)$, find $i_1(0^+)$.
  3. Find $i_1(\infty)$.
  4. Let $i_1(t)=A\,e^{-t/\tau} + B$ for $t > 0$. Using $i_1(0^+)$ and $i_1(\infty)$, find $A$ and $B$.
  5. Obtain $\tau$ using the condition $i_1=45\,$mA at $t=0.1\,$msec.
  6. From $\tau$, find $C$.
In [1]:
from IPython.display import Image
Image(filename =r'time_constant_4_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 time_constant_4_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 time_constant_4_orig.in and produces a new circuit file time_constant_4.in, after replacing \$C with the value of our choice.

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

The circuit file (time_constant_4.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on time_constant_4.in) creates the data file time_constant_4_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_4.in")

i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)

IR2_dc = slv.get_scalar_double(i_slv, i_out, 'IR2', u)
IC_dc  = slv.get_scalar_double(i_slv, i_out, 'IC',  u)
VC_dc  = slv.get_scalar_double(i_slv, i_out, 'VC',  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]
IR20 = 45.0e-3

IR2 = slv.get_array_double(i_slv, i_out, 'IR2', u)
IC  = slv.get_array_double(i_slv, i_out, 'IC',  u)
VC  = slv.get_array_double(i_slv, i_out, 'VC',  u)

ta = -0.02e-3
tb = 0.0
t_1 = np.array([ta, tb])
IR2_1 = np.array([IR2_dc, IR2_dc])
IC_1  = np.array([IC_dc,  IC_dc])
VC_1  = np.array([VC_dc,  VC_dc])

t_2   = np.concatenate((t_1,   t))
IR2_2 = np.concatenate((IR2_1, IR2))
IC_2  = np.concatenate((IC_1,  IC))
VC_2  = np.concatenate((VC_1,  VC))

l_cross_1, l_cross_2 = calc.cross_over_points_1(t, IR2, 0.0, t_end, IR20)
print('time points at which i1 crosses', "%5.2f"%(IR20*1.0e3), "mA")
for t1 in l_cross_2:
    print("  ", "%5.2f"%(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=20.0, top=110.0)
ax[2].set_ylim(bottom=2.0,  top=10.5)

ax[0].set_ylabel(r'$i_1$ (mA)', fontsize=12)
ax[1].set_ylabel(r'$i_C$ (mA)', fontsize=12)
ax[2].set_ylabel(r'$V_C$ (V)',  fontsize=12)

ax[0].tick_params(labelbottom=False)
ax[1].tick_params(labelbottom=False)

ax[0].plot(t_2*1e3, IR2_2*1e3, color=color1, linewidth=1.0, label="$i_1$")
ax[1].plot(t_2*1e3, IC_2*1e3,  color=color1, linewidth=1.0, label="$i_C$")
ax[2].plot(t_2*1e3, VC_2,      color=color2, linewidth=1.0, label="$V_C$")

ax[0].axhline(y = IR20*1e3, 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 (msec)', fontsize=11)

#plt.tight_layout()
plt.show()
filename: time_constant_4_1.dat
filename: time_constant_4_2.dat
time points at which i1 crosses 45.00 mA
    0.05 msec
No description has been provided for this image

This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.

In [ ]: