Python Forum
I tried to solve basic reaction kinetics ode but i cant run the simulation. Plz help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I tried to solve basic reaction kinetics ode but i cant run the simulation. Plz help
#1
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

def rxn(Z, t):
    k1 = 1
    k2 = 1.5
    
    r1 = k1*Z[0]*Z[1]
    r2 = k2*Z[1]*Z[2]
    
    dAdt = -r1
    dBdt = -r1 -r2
    dCdt = r1 -r2
    dDdt = r2
    return[dAdt,dBdt,dCdt,dDdt]

t = np.arange(0,3.01,0.2)
Z0 = [1,1,0,0]
Conc = odeint(rxn(Z0,t))

cA = Conc[:,0]
cB = Conc[:,1]
cC = Conc[:,2]
cD = Conc[:,3]

S = np.empty(len(cC))
for i in range(len(cC)):
    if abs(cC[i]+cD[i]>1e-10):
        S[i] = cC/(cC+cD)
    else:
        S[i] = 1.0

plt.plot(t,cA)
plt.plot(t,cB)
plt.plot(t,cC)
plt.plot(t,cD)
plt.xlabel(time)
plt.ylabel(Concentration)
plt.legend('Ca','Cb','Cc','Cd')
Larz60+ write Feb-08-2022, 12:14 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBcode tags on future posts.
Reply
#2
Tried running, you are missing arguments:
Error:
Traceback (most recent call last): File "/media/larz/Projects/projects/QRST/T/TryStuffNew/src/Feb_8_2022_1.py", line 20, in <module> Conc = odeint(rxn(Z0,t)) TypeError: odeint() missing 2 required positional arguments: 'y0' and 't'
Vengdasan likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Hi can you help me this reaction kinetics Vengdasan 4 1,476 Feb-13-2022, 01:05 PM
Last Post: jefsummers
  Help with simulation Geeseball 0 2,090 Oct-18-2018, 12:19 PM
Last Post: Geeseball

Forum Jump:

User Panel Messages

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