Python如何将ODE与CSVD结合起来

2024-09-29 23:16:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将稳态微分方程组与随时间变化的CSV数据相结合

我已经设法弄清楚了如何分别绘制数据,只是将它们结合在一起,这让我感到困扰(我是Python初学者)。”ODE中的“dC1dt”是来自相关CSV的附加数据:

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# Model
def model(C,t):

    C1 = 400
    C2 = 600
    C3 = 900

    K1 = 3
    K2 = 4
    K3 = 9
    K4 = 10
    #A = 

    dC1dt = (K1 * C2 - K2 * C1) # + A
    dC2dt = (K3 * C3 - K4 * C2) + (K2 * C1 - K1 * C2)
    dC3dt = K4 * C2 - K3 * C3
    return dC1dt + dC2dt + dC3dt

# Initial condition
C0 = 400

# Time points
t = np.linspace(0,3000,num=1000)

# Solve ODE
C = odeint(model,C0,t)

# Plot results
plt.plot(t,C)
plt.xlabel('Time')
plt.ylabel('Variable')
plt.title('Model')
plt.show()

CSV只有两列:

可变时间

10,1

20,3

30,8

等等

CSV中的数据随时间呈指数增长,因此最终结果应显示出增长趋势。任何帮助都将不胜感激


Tags: csv数据importas时间pltk2k1

热门问题