本文介绍了将硬ODE与Python集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个很好的库,它将在Python中集成严格的ODE.问题是,scipy的颂歌有时会给我很好的解决方法,但初始条件中的最细微变化都会使它跌落并放弃. 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存在的特定问题是选择正确的步进功能.其中有几种,但没有与ode15或ode23的直接类似物(如果有意义,则使用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 .它是公共领域.您可以下载 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集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:25