问题描述
我正在寻找一个可以在 Python 中集成刚性 ODE 的好库.问题是,scipy 的 odeint 给了我很好的解决方案有时,但初始条件的最轻微变化都会导致它崩溃并放弃.MATLAB 的刚性求解器(ode15s 和 ode23s)很高兴地解决了同样的问题,但我不能使用它(即使是从 Python 中,因为 MATLAB C API 的 Python 绑定都没有实现回调,我需要传递一个函数到 ODE 求解器).我正在尝试 PyGSL,但它非常复杂.任何建议将不胜感激.
I'm looking for a good library that will integrate stiff ODEs in Python. The issue is, scipy's odeint gives me good solutions sometimes, but the slightest change in the initial conditions causes it to fall down and give up. The same problem is solved quite happily by MATLAB's stiff solvers (ode15s and ode23s), but I can't use it (even from Python, because none of the Python bindings for the MATLAB C API implement callbacks, and I need to pass a function to the ODE solver). I'm trying PyGSL, but it's horrendously complex. Any suggestions would be greatly appreciated.
我在使用 PyGSL 时遇到的具体问题是选择正确的步进函数.其中有几个,但没有与 ode15s 或 ode23s 的直接类似物(bdf 公式和修改后的 Rosenbrock,如果有意义的话).那么,为刚性系统选择一个好的阶跃函数是什么?我必须解决这个系统很长时间才能确保它达到稳态,而 GSL 求解器要么选择一个很小的时间步长,要么选择一个太大的时间步长.
The specific problem I'm having with PyGSL is choosing the right step function. There are several of them, but no direct analogues to ode15s or ode23s (bdf formula and modified Rosenbrock if that makes sense). So what is a good step function to choose for a stiff system? I have to solve this system for a really long time to ensure that it reaches steady-state, and the GSL solvers either choose a miniscule time-step or one that's too large.
推荐答案
Python可以调用C.行业标准是LSODE 在 ODEPACK 中.它是公共领域的.您可以下载 C 版.这些求解器非常棘手,因此最好使用一些经过良好测试的代码.
Python can call C. The industry standard is LSODE in ODEPACK. It is public-domain. You can download the C version. These solvers are extremely tricky, so it's best to use some well-tested code.
补充:确保你真的有一个刚性系统,即如果速率(特征值)相差超过 2 或 3 个数量级.此外,如果系统是刚性的,但您只是在寻找稳态解,这些求解器可为您提供代数求解某些方程的选项.否则,像 DVERK 这样的优秀 Runge-Kutta 求解器将成为一个很好的、更简单的解决方案.
Added: Be sure you really have a stiff system, i.e. if the rates (eigenvalues) differ by more than 2 or 3 orders of magnitude. Also, if the system is stiff, but you are only looking for a steady-state solution, these solvers give you the option of solving some of the equations algebraically. Otherwise, a good Runge-Kutta solver like DVERK will be a good, and much simpler, solution.
添加在这里是因为它不适合评论:这是来自 DLSODE 标题文档:
Added here because it would not fit in a comment: This is from the DLSODE header doc:
C T :INOUT Value of the independent variable. On return it
C will be the current value of t (normally TOUT).
C
C TOUT :IN Next point where output is desired (.NE. T).
此外,是的,Michaelis-Menten 动力学是非线性的.不过,Aitken 加速器可以与之配合使用.(如果你想要一个简短的解释,首先考虑 Y 是标量的简单情况.你运行系统以获得 3 个 Y(T) 点.通过它们拟合指数曲线(简单代数).然后将 Y 设置为渐近线和重复.现在只是概括为 Y 是一个向量.假设 3 个点在一个平面上 - 如果它们不在也没关系.)此外,除非你有一个强制函数(比如一个恒定的 IV 点滴),否则 MM 消除会衰减离开,系统将接近线性.希望有所帮助.
Also, yes Michaelis-Menten kinetics is nonlinear. The Aitken acceleration works with it, though. (If you want a short explanation, first consider the simple case of Y being a scalar. You run the system to get 3 Y(T) points. Fit an exponential curve through them (simple algebra). Then set Y to the asymptote and repeat. Now just generalize to Y being a vector. Assume the 3 points are in a plane - it's OK if they're not.) Besides, unless you have a forcing function (like a constant IV drip), the MM elimination will decay away and the system will approach linearity. Hope that helps.
这篇关于将刚性 ODE 与 Python 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!