python - timestep variable in ODEINT -


first let me apologize if simple question, or has been answered before. truth don't know how run search question.

let's have following set of coupled ode:

dn/dt = (hn(t) + iq(t))*g(t)

dq/dt = (jn(t) + lq(t))*g(t)

this code used plot odes:

import numpy  import matplotlib.pyplot plt scipy import constants scipy.integrate import odeint plt.ion()  #-------------------------------------initial constant parameters-------------------------------------------  wavelenght      = 1908e-9 #meter wp0             = 300e-6 #laser beam diameter conc            = 1.0 #dopant concentration crosssection    = 6.5e-14 #spectroscopic absorption cross section in m2 lifetime        = 230e-6 #upper lifetime cavity_l        = 200e-3 #total lenght of cavity in mm gain_l          = 10e-3 #lenght of gain medium n_gain          = 1.82 #refraction index gain medium r_oc            = 0.3 #reflectivity oc additional_loss = 0.05 #additional losses loss_time_max   = 10.0e5 #max loss instroduced q-switch r               = 10 #times above threshold laser pumped before q-switch opens t0              = 0 tf              = 20e-12 tpulse          = 1e-9 ttotal          = 10e-9  #-------------------------------------initial variable parameters-------------------------------------------  #number density concentration percentage ntotalyag             = conc*3*4.55/((3*88.9 + 5*27.0 + 12*16.0)*constants.m_p) #nominator: 3 @ of y * mass density of y3al5o12 #denominator: mass of y3al5o12 unit, calculated relative atomic weights , proton mass  beam_area             = numpy.pi*(wp0/2)*(wp0/2)  roundtrip_time        = 2.0*((cavity_l-gain_l)/constants.c)+(n_gain*gain_l/constants.c) #time light travel , forth inside cavity  losscoef              = - numpy.log(r_oc) + additional_loss   popinversionthreshold = losscoef * beam_area/(2.0 * crosssection)  wp = 0.0 #pumping rate  #-------------------------------------functions-------------------------------------------  def f(y, t, l):     q      = y[0]     deltan = y[1]     if t > tf:         losscoef_t = 0.0     else:         losscoef_t = loss_time_max - ((loss_time_max - losscoef)/(tf))*t     # gupta handbook of photonics ch micro laser     l= l.append(losscoef_t)     f0 = q*((deltan/popinversionthreshold)-1.0) * losscoef_t/roundtrip_time     f1 = wp*(ntotalyag-deltan) - q*((deltan*losscoef_t)/(popinversionthreshold*roundtrip_time)) - deltan/lifetime     return [f0, f1]  #-------------------------------------ode solving 1------------------------------------------- # initial conditions q0 = 0.01               # initial photon population deltan0 = r * popinversionthreshold   # initial inverted population y0 = [q0, deltan0]       # initial condition vector t  = numpy.linspace(0, ttotal, 1000)   # time grid  l = []  # solve des soln = odeint(f, y0, t, args=(l,)) q    = soln[:, 0]  n    = soln[:, 1]   #-------------------------------------plots---------------------------------------------------  plt.figure() plt.plot(t, q, label='photon') plt.plot(t, n, label='population') plt.legend(loc=0) 

the above not work, since assumed calculate g(t) each timestep t, noticed len(l) not same q or n. question is, how calculate parameter on ode varies timestep t?

thanks lot


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -