Integration using scipy odeint
sagark9299 at gmail.com
Sun Sep 13 16:49:37 CEST 2015
I'm using Python 3.4.3. I am facing a problem in integrating using odeint solver. In the following code, tran is a function and in those are the variables which are arrays. These variables change their values with respect to time (the time which I pass to the function). I tried defining a loop inside the function, but Python throws an error saying float object not iterable. Please guide me how to solve this problem.
#initial is an array containing initial values for the integration, dt is the time array with unequal time steps, which I have captured from other part of the code
for i in dt:
k1 [i] = 2.8e8 * math.exp(-21100/ta[i]) # k1,k2,k3 & k4 are constants which change according to temperature (ta), which in turn changes with respect to time.
k2 [i] = 1.4e2 * math.exp(-12100/ta[i]) # ta changes its values according to dt, which is array. It runs from 0-6 with unequal time steps.
k3 [i] = 1.4e5 * ta[i] * math.exp(-19680/ta[i]) # I've captured dt and all other arrays here from another loop, which is not of importtance.
k4 [i] = 1.484e3 * ta[i]
y = initial
z = initial
dn = (6*rho*initial)
dd = (math.pi*2000*initial)
ds = (dn/dd)**1/3
dydt = (166.2072*ta[i]*cca[i] - (1.447e13 * ta[i]**0.5 * rho**1/6 * y**1/6 * rho**1/6 * z**1/6 * 0.0832)) # cca,ta are arrays. y & z are 2 dependent variables
dzdt = (k1[i]*ta[i]*cca[i]*12.011 + (21.2834*k2[i]*ta[i]*cca[i] * y**1/2 *ds) - (k3[i]*ta[i]*12.011*y*math.pi*ds**2 * cco[i]) -
return [dydt,dzdt] # dydt & dzdt are my final time integrated values
initial = [0.01,1e-5]
sol = odeint(tran, initial, dt) #this is my function call
If I pass array in my function call, it says only length-1 can be converted to Python scalars.
So I request all the experts in the group to tell me where I'm going wrong.
More information about the Python-list