DC circuits

In the circuit shown in the figure, the current $i$ is $2.33\,$A.
  1. Find $I_S$. (Hint: use superposition.)
  2. Without solving the circuit equations again, find $i$ if $V_{S1}$, $V_{S2}$, $I_S$ are made $10\,$V, $5\,$V, and $2\,$A, respectively.
In [1]:
from IPython.display import Image
Image(filename =r'dc_circuit_6_fig_1.png', width=340)
Out[1]:
No description has been provided for this image
In [2]:
# run this cell to view the circuit file.
%pycat dc_circuit_6_orig.in

We now replace strings such as \$Is with the values of our choice by running the python script given below. It takes an existing circuit file dc_circuit_6_orig.in and produces a new circuit file dc_circuit_6.in, after replacing \$Is, etc with the values of our choice.

In [3]:
# Use this for part 1 of the question

import gseim_calc as calc
s_Vs1 = '5'
s_Vs2 = '2'
s_Is = '2' # to be changed by user
l = [
  ('$Vs1', s_Vs1),
  ('$Vs2', s_Vs2),
  ('$Is', s_Is),
]
calc.replace_strings_1("dc_circuit_6_orig.in", "dc_circuit_6.in", l)
print('dc_circuit_6.in is ready for execution')
dc_circuit_6.in is ready for execution
Execute the following cell to run GSEIM on dc_circuit_6.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("dc_circuit_6.in")
os.system('run_gseim dc_circuit_6.in')
Circuit: filename = dc_circuit_6.in
main: i_solve = 0
GSEIM: Program completed.
Out[4]:
0

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

slv = calc.slv("dc_circuit_6.in")

i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
VA = slv.get_scalar_double(i_slv, i_out, "VA", u)
VB = slv.get_scalar_double(i_slv, i_out, "VB", u)
VC = slv.get_scalar_double(i_slv, i_out, "VC", u)
VD = slv.get_scalar_double(i_slv, i_out, "VD", u)
IR1 = slv.get_scalar_double(i_slv, i_out, "IR1", u)
IR2 = slv.get_scalar_double(i_slv, i_out, "IR2", u)
IR3 = slv.get_scalar_double(i_slv, i_out, "IR3", u)
IR4 = slv.get_scalar_double(i_slv, i_out, "IR4", u)

s_format = "%7.2f"

calc.print_double_1('VA', VA, s_format)
calc.print_double_1('VB', VB, s_format)
calc.print_double_1('VC', VC, s_format)
calc.print_double_1('VD', VD, s_format)

s_format_1 = "%11.4E"

calc.print_double_1('IR1', IR1, s_format_1)
calc.print_double_1('IR2', IR2, s_format_1)
calc.print_double_1('IR3', IR3, s_format_1)
calc.print_double_1('IR4', IR4, s_format_1)
filename: dc_circuit_6.dat
VA:   10.13
VB:    6.47
VC:    3.47
VD:    1.47
IR1:  1.2667E+00
IR2:  7.3333E-01
IR3:  7.3333E-01
IR4:  3.7500E-01
In [6]:
# Use this for part 2 of the question

import gseim_calc as calc
s_Vs1 = '10'
s_Vs2 = '5'
s_Is = '2'
l = [
  ('$Vs1', s_Vs1),
  ('$Vs2', s_Vs2),
  ('$Is', s_Is),
]
calc.replace_strings_1("dc_circuit_6_orig.in", "dc_circuit_6.in", l)
print('dc_circuit_6.in is ready for execution')
dc_circuit_6.in is ready for execution
Execute the following cell to run GSEIM on dc_circuit_6.in.
In [7]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("dc_circuit_6.in")
os.system('run_gseim dc_circuit_6.in')
Circuit: filename = dc_circuit_6.in
main: i_solve = 0
GSEIM: Program completed.
Out[7]:
0
In [8]:
import numpy as np
import gseim_calc as calc

slv = calc.slv("dc_circuit_6.in")

i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
VA = slv.get_scalar_double(i_slv, i_out, "VA", u)
VB = slv.get_scalar_double(i_slv, i_out, "VB", u)
VC = slv.get_scalar_double(i_slv, i_out, "VC", u)
VD = slv.get_scalar_double(i_slv, i_out, "VD", u)
IR1 = slv.get_scalar_double(i_slv, i_out, "IR1", u)
IR2 = slv.get_scalar_double(i_slv, i_out, "IR2", u)
IR3 = slv.get_scalar_double(i_slv, i_out, "IR3", u)
IR4 = slv.get_scalar_double(i_slv, i_out, "IR4", u)

s_format = "%7.2f"

calc.print_double_1('VA', VA, s_format)
calc.print_double_1('VB', VB, s_format)
calc.print_double_1('VC', VC, s_format)
calc.print_double_1('VD', VD, s_format)

s_format_1 = "%11.4E"

calc.print_double_1('IR1', IR1, s_format_1)
calc.print_double_1('IR2', IR2, s_format_1)
calc.print_double_1('IR3', IR3, s_format_1)
calc.print_double_1('IR4', IR4, s_format_1)
filename: dc_circuit_6.dat
VA:   12.80
VB:   10.80
VC:    5.80
VD:    0.80
IR1:  1.6000E+00
IR2:  4.0000E-01
IR3:  4.0000E-01
IR4:  6.2500E-01

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

In [ ]: