首页 文章

用odeint求解耦合颂歌系统

提问于
浏览
0

我正在使用ode系统来模拟咖啡 beans 烘焙以进行课堂作业 . 方程式如下 .

Systems of Equations

参数(X_b和T_b除外)都是常量 .

当我尝试使用odeint来解决这个系统时,它给出了一个恒定的T_b和X_b配置文件(概念上没有意义) .

下面是我正在使用的代码

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

# Write function for bean temperature T_b differential equation
def deriv(X,t):
    T_b, X_b = X 
    dX_b = (-4.32*10**9*X_b**2)/(l_b**2)*np.exp(-9889/T_b)
    dT_b = ((h_gb*A_gb*(T_gi - T_b))+(m_b*A_arh*np.exp(-H_a/R_g/T_b))+ 
    (m_b*lam*dX_b))/(m_b*(1.099+0.0070*T_b+5*X_b)*1000)
    return [dT_b, dX_b]

# Establish initial conditions
t = 0 #seconds
T_b = 298 # degrees K
X_b = 0.1 # mass fraction of moisture

# Set time step
dt = 1 # second

# Establish location to store data
history = [[t,T_b, X_b]]

# Use odeint to solve DE
while t < 600:
  T_b, X_b = odeint(deriv, [T_b, X_b], [t+dt])[-1]
  t += dt
  history.append([t,T_b, X_b])

# Plot Results
def plot_history(history, labels):
  """Plots a simulation history."""
  history = np.array(history)
  t = history[:,0]
  n = len(labels) - 1
  plt.figure(figsize=(8,1.95*n))
  for k in range(0,n):
    plt.subplot(n, 1, k+1)
    plt.plot(t, history[:,k+1])
    plt.title(labels[k+1])
    plt.xlabel(labels[0])
    plt.grid()
  plt.tight_layout()


plot_history(history, ['t (s)','Bean Temperature $T_b$ (K)', 'Bean Moisture Content $X_b$'])
plt.show()

您有什么想法为什么整合步骤不起作用?

谢谢!!

1 回答

  • 0

    你只是在一个时间点上反复求解方程组 .

    odeint documentation开始, odeint 命令采用参数 t ,即:

    为y求解的一系列时间点 . 初始值点应该是此序列的第一个元素 .

    由于您将 [t+dt] 传递给 odeint ,因此只有一个时间点,因此您只返回一个值,这只是您的初始条件 .

    使用 odeint 的正确方法类似于以下内容:

    output = odeint(deriv, [T_b, X_b], np.linspace(0,600,600))
    

    这里 output ,再次根据文档是:

    包含t中每个所需时间的y值的数组,第一行中的初始值为y0 .

相关问题