math - Python coding for ODE System -


i have system of equations described function in which.

  1. products constructed reactants
  2. some products break down
  3. some percentage of broken down products recycled initial reactants
  4. the system continues cycle more products being made until of limiting reactant within non-cycling product or unusable "lost products"

given products not change in composition. need amount of reactant 1 going system being directly proportional amount of reactant 2 going system. thus, when of reactant 1 consumed, no more of reactant 2 consumed.

currently ratio of reactant consumption constant when there no recycling of reactants, however, when reactants cycled in lines react1=-r1 - r5 , react2=-r2 - r6 ratio of reactants used altered.

the second issue during cycling product 2 , lost products not continually increasing. instead seem maintaining fixed ratio product 1 , recycled products respectively.

i assume both issues caused how have attempted recycle reactants within system. appreciated.

import numpy np scipy.integrate import odeint import matplotlib.pyplot plt import math import pylab p  def sample_func (y,t):       k1 = 10**-4     k2 = k1/4     k3 = 0.1     recycle0=0.8     recycle2=0.7       r1= -k1*y[0]*y[2]  # rate of substance 1 consumption     r2= -k2*y[0]*y[2]  # rate of substance 2 consumption      #these must proportional 1       r3= 0.2*r1+0.7*r2    #product 1     r4= 0.8*r1+0.3*r2    #product 2       r5=r3*recycle0      #recycled substance 1 of product 1       r6=r3*recycle2      #recycled substance 2 of product 1      r7=r3*(1-recycle0)     r8=r3*(1-recycle2)      used1 =     r1     react1=     -r1 - r5      used2 =     r2     react2=     -r2 - r6     prod1=      -r3      prod2=      -r4     recycledr1 =-r5     recycledr2 =-r6     lost1      =-r7     lost2      =-r8      return [used1, react1, used2,react2,prod1,prod2, recycledr1,recycledr2,lost1,lost2]      y0=(3,11,3,12,0.01,0.01,0.01,0.01,0.01,0.01) tspan=np.arange(0,15000,1) conc= odeint(sample_func,y0,tspan)    react1          = conc[:,0] used1           = conc[:,1]  react2          = conc[:,2] used2           = conc[:,3] prod1           = conc[:,4] prod2           = conc[:,5] recycledr1      = conc[:,6] recycledr2      = conc[:,7]  print("consumed r1 & r2 ratios @ different time points") print((conc[1:2,1]-conc[0:1,1])/(conc[1:2,3]-conc[0:1,3]), " 1 hours") print((conc[50:51,1]-conc[0:1,1])/(conc[50:51,3]-conc[0:1,3]), "50 hours") print((conc[1000:1001,1]-conc[0:1,1])/(conc[1000:1001,3]-conc[0:1,3]), "1000 hours")  plt.plot(tspan,react1,label='react1') plt.plot(tspan,used1,label='used1') plt.plot(tspan,react2,label='react2') plt.plot(tspan,used2,label='used2') plt.plot(tspan,prod1,label='product1') plt.plot(tspan,prod2,label='product2') plt.plot(tspan,recycledr1,label='recycled react 1') plt.plot(tspan,recycledr2,label='recycled react 2')   plt.xlabel("time (hours)") plt.ylabel("quantity") plt.title("production v time") plt.legend()  p.show() 

regards.

op duffymo offers sound observation, in opinion. should have individual ode each reactant. having dealt problems of nature myself few times, have few pieces of advice:

-if each ode mass action laws linear (i.e. no concentrations multiplied together) implicit approach implemented. i'd suggest starting "trapezoidal method" , implementing higher order integration schemes ad nausea.

-if system nonlinear problem bit more difficult solve. if magnitudes of of euqilibrium/rate constants similar can use explicit integration scheme without trouble. explicit rk4 shouldn't hard implement.

-i suggest verifying whatever system of differential equations develop against mass action derivations published in scientific literature, if chemical kinetics not area of expertise. if commonly investigated chemical system such derivation should not hard find.

-if mass action system has been setup correctly , integration scheme working conservation of mass should visibly maintained. verify this, select element of system has equal stoichiometric coefficients in forms (i.e. carbon in co2 , co) , verify it's abundance in system constant.

here link might started setting mass action odes

law of mass action


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -