Inductor in periodic steady state

The voltage $v_L(t)$ (with period $1\,\mu$s) across a $10\,\mu$H inductor is given below, with $V_1=20\,$V, $V_2=-15\,$V. The current through the inductor is in cyclic steady state with an average value of $5\,$A.
  1. Find the duty ratio $D$.
  2. What is the maximum instantaneous energy stored in the inductor?
In [1]:
from IPython.display import Image
Image(filename =r'misc_9_fig_1.png', width=220)
Out[1]:
No description has been provided for this image
In [2]:
import numpy as np
import matplotlib.pyplot as plt 
import gseim_calc as calc
from setsize import set_size
import sys

V1 = 20.0
V2 = -15.0
D = 0.3 # to be changed by user
T = 1.0e-6
L = 10.0e-6

n_div = 5000
t = np.linspace(0.0, 2*T, (n_div+1))

DT = D*T

l_vl = []
for i, u in enumerate(t):
    t1 = u % T
    if t1 < DT:
        vl1 = V1
    else:
        vl1 = V2
    l_vl.append(vl1)

x_vl = np.array(l_vl)

l_x_vl = calc.avg_rms_2(t, x_vl, 0.0, 2.0*T, 1.0e-5*T)
t_vl = np.array(l_x_vl[0])

if abs(l_x_vl[1][0]) > (1.0e-3*V1):
    print('average value of VL:', "%11.4E"%l_x_vl[1][0])
    print('D =', "%11.4E"%D, 'is not correct. Halting...')
#   the rest of the calculation will not make sense if D is not correct.
#   Skip it.
else:
    print('D =', "%11.4E"%D, 'is correct')

    ILav = 5.0

    ILmin = 0.5*(2.0*ILav - V1*DT/L)
    print('ILmin =', "%11.4E"%ILmin)

    l_il = []
    il = ILmin
    l_il.append(il)

    delt = 2.0*T/float(n_div)
    c1 = delt/L

    for k in range(1,len(t)):
        il += c1*l_vl[k]
        l_il.append(il)

    x_il = np.array(l_il)
    il_max = x_il.max()
    il_min = x_il.min()

    l_x_il = calc.avg_rms_2(t, x_il, 0.0, 2.0*T, 1.0e-5*T)
    t_il = np.array(l_x_il[0])
    print('average value of IL:', "%11.4E"%l_x_il[1][0])
    print('minimum value of IL:', "%11.4E"%x_il.min())
    print('maximum value of IL:', "%11.4E"%x_il.max())

    E = 0.5*L*x_il*x_il
    E_max = E.max()
    print('maximum inductor energy:', "%11.4E"%E_max)

    fig, ax = plt.subplots(3, sharex=False)
    plt.subplots_adjust(wspace=0, hspace=0.0)
    grid_color='#CCCCCC'

    set_size(6, 5, ax[0])

    color1 ='blue'
    color2 ='crimson'
    color3 ='olive'

    for k in range(3):
        ax[k].set_xlim(left=0.0, right=2.0*T*1e6)
        ax[k].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)

    ax[0].set_ylabel('$v_L$',fontsize=13)
    ax[1].set_ylabel('$i_L$',fontsize=13)
    ax[2].set_ylabel('$E$',fontsize=13)

    ax[0].tick_params(labelbottom=False)
    ax[1].tick_params(labelbottom=False)
    ax[2].set_xlabel(r'$t$ ($\mu$sec)',fontsize=13)

    ax[0].plot(t*1e6, x_vl, color=color1, linewidth=1.0, label="$v_L$")
    ax[1].plot(t*1e6, x_il, color=color2, linewidth=1.0, label="$i_L$")
    ax[2].plot(t*1e6, E   , color=color3, linewidth=1.0, label="$E$")

    ax[0].plot(t_vl*1e6, l_x_vl[1], color=color1, linewidth=1.0, label="$v_L^{avg}$", linestyle='-.')
    ax[1].plot(t_il*1e6, l_x_il[1], color=color2, linewidth=1.0, label="$i_L^{avg}$", linestyle='-.')

    for k in [0,1]:
        ax[k].legend(loc = 'upper right',frameon = True, fontsize = 10, title = None,
           markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
           prop = {'size' : 12},)

#   plt.tight_layout()
    plt.show()
average value of VL: -4.4930E+00
D =  3.0000E-01 is not correct. Halting...

This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.

In [ ]: