odeint 方程系统的动态生成
Dynamic generatation of equation system for odeint
我有一个用于 odeint
Python 模块的 ODE 系统:
def equations(p, t, lmbds):
return np.array([-p[0] * lmbds[0] + p[1] * lmbds[1],
-p[1] * lmbds[1] - p[1] * lmbds[2] + p[0] * lmbds[0]])
该系统对应于二态三强度的马尔可夫链。
方程组可以包含不同数量的方程。是否可以根据用户输入的方程式数量随时生成它们?
请看下面创建n个方程的方法:
def get_equation(p, t, lmbds, n):
""" Returns equation for provided n. """
# Create and return equation
def equations(p, t, lmbds, eq_num):
equations = []
for n in range(eq_num):
equation = get_equation(p, t, lmbds, n)
equations.append(equation)
return np.array(*equations)
我有一个用于 odeint
Python 模块的 ODE 系统:
def equations(p, t, lmbds):
return np.array([-p[0] * lmbds[0] + p[1] * lmbds[1],
-p[1] * lmbds[1] - p[1] * lmbds[2] + p[0] * lmbds[0]])
该系统对应于二态三强度的马尔可夫链。
方程组可以包含不同数量的方程。是否可以根据用户输入的方程式数量随时生成它们?
请看下面创建n个方程的方法:
def get_equation(p, t, lmbds, n):
""" Returns equation for provided n. """
# Create and return equation
def equations(p, t, lmbds, eq_num):
equations = []
for n in range(eq_num):
equation = get_equation(p, t, lmbds, n)
equations.append(equation)
return np.array(*equations)