DC circuits

In the circuit shown in the figure, the maximum power supplied to $R_L$ is $977\,$mW. Find $I_S$.
In [1]:
from IPython.display import Image
Image(filename =r'dc_circuit_5_fig_1.png', width=300)
Out[1]:
No description has been provided for this image
In [2]:
# run this cell to view the circuit file.
%pycat dc_circuit_5_orig.in

We now replace the string \$Is with the value of our choice by running the python script given below. It takes an existing circuit file dc_circuit_5_orig.in and produces a new circuit file dc_circuit_5.in, after replacing \$Is with the value of our choice.

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

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

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

RL = slv.get_array_double(i_slv, i_out, 'RL', u)
PL = slv.get_array_double(i_slv, i_out, 'PL', u)

k_max = np.argmax(PL)
s_format = "%11.4E"
calc.print_double_1('RL (approx) for maximum power:', RL[k_max], s_format)
calc.print_double_1('maximum power:', PL[k_max], s_format)

color1='green'

fig, ax = plt.subplots()
plt.subplots_adjust(wspace=0, hspace=0.0)

set_size(4, 2.5, ax) 

plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)

ax.plot(RL, PL, color=color1, linewidth=1.0, label="$P_L$")

plt.xlabel(r'$R_L\,(\Omega)$', fontsize=11)
plt.ylabel(r'$P_L\,$' + '(W)', fontsize=11)

plt.tight_layout()
plt.show()
filename: dc_circuit_5.dat
RL (approx) for maximum power::  1.6106E+00
maximum power::  3.9062E+00
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 [ ]: