Skip to content

Examples

Example 1:

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

# 定义模型
def model(y, t):
  k1, k2 = 0.1, 0.1
  dydt = [k1 * y[0], k2 * y[1]]
  return dydt

# 初始条件
y0 = [1, 0]

# 时间范围
t = np.linspace(0, 10, 1000)

# 求解
y = odeint(model, y0, t)

# 绘制结果
plt.plot(t, y[:, 0], label='X')
plt.plot(t, y[:, 1], label='Y')
plt.xlabel('Time')
plt.ylabel('Concentration')
plt.legend()
plt.show()