Python Forum
Hi can you help me this reaction kinetics
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hi can you help me this reaction kinetics
#1
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math

def rxn(M,t):
    R = 8.314
    T = 415
    
    K1 = (2.19*10**-1)*(math.exp((-1.148*10**5)/R*T)) #KTi
    K2 = (1.051*10**4)*(math.exp((-2.957*10**4)/R*T)) #Kp
    K3 = (2.31*10**3)*(math.exp((-5.302*10**4)/R*T)) #Ktrm
    K4 = (2.0497*10**3)*(math.exp((-5.24*10**4)/R*T)) #Ktrs
    K5 = (6.275*10**5)*(math.exp((-7.026*10**4)/R*T)) #Ktc
    K6 = 0
    
    dMdt = -2*K1*(M[1]**3)-(K2+K3)*(M[1])*(M[3])
    dSdt = -K4*M[2]*M[3]
    dY0dt = 2*K1*(M[1]**3)-(K5+K6)*M[3]**2
    dU0dt = K3*M[3]*M[1]+K4*M[3]*M[2]+K6*M[3]**2+0.5*K5*M[3]**2
    dY1dt = 2*K1*M[1]**3+K2*M[1]*M[3]-K3*M[1](M[3]-M[4])-K4*M[2]*(M[3]-M[4])-(K5+K6)*M[3]*M[4]
    dU1dt = K3*M[4]*M[1]+K4*M[4]*M[2]+(K5+K6)*M[3]*M[4]
    return (dMdt,dSdt,dY0dt,dU0dt,dY1dt,dU1dt)

t = np.linspace(0,400,20)
M0 = [7632.2,587.47,0,0,0]
Conc = odeint(rxn,M0,t)

cM = Conc[:,0]
cS = Conc[:,1]
cY0 = Conc[:,2]
cU0 = Conc[:,3]
cY1 = Conc[:,4]
cU1 = Conc[:,5]


plt.plot(t,cM)
plt.plot(t,cS)
plt.plot(t,cY0)
plt.plot(t,cU0)
plt.plot(t,cY1)
plt.plot(t,cU1)
plt.xlabel('time')
plt.ylabel('Concentration')
Error:
'numpy.float64' object is not callable
Reply
#2
Need the complete error code. Lots of added info that is needed to analyze. Complete code as well.
Reply
#3
When I run the posted script just as it is, I get:
Error:
Traceback (most recent call last): File "tester.py", line 31, in <module> Conc = odeint(rxn,M0,t) File "/home/bash/.local/lib/python3.8/site-packages/scipy/integrate/odepack.py", line 241, in odeint output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu, File "tester.py", line 25, in rxn dY1dt = 2*K1*M[1]**3+K2*M[1]*M[3]-K3*M[1](M[3]-M[4])-K4*M[2]*(M[3]-M[4])-(K5+K6)*M[3]*M[4] TypeError: 'numpy.float64' object is not callable shell returned 1
Reply
#4
Actually, I have to do virtual lab using python GUI. For that I have use and solve some odes that other researchers drive. Here are the odes and constants. Actually I learn MATLAB only my lecturers also mastered in MATLAB only. I hope u guys can help me to do my project I will post credits for u all in my report.

Equation : https://drive.google.com/file/d/1OnJNGV7...sp=sharing
K constant : https://drive.google.com/file/d/1qiwTLp6...sp=sharing
Reply
#5
I see the error. In that line (21 in your posted code, 25 when BashBedlam ran it) you need an operator in the middle of
(Feb-11-2022, 03:54 PM)Vengdasan Wrote: K3*M[1](M[3]-M[4])

As it stands, you are calling M[1] a function which it is not, because M[1] is followed immediately by the parentheses.
ibreeden and Vengdasan like this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I tried to solve basic reaction kinetics ode but i cant run the simulation. Plz help Vengdasan 1 1,238 Feb-08-2022, 12:16 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020