Python - Scipy:ode模块:启用求解器步长选项的问题

6

我希望在调用求解器时,能够存储其自身所采取的不同集成步骤:

solver1.integrate(t_end)

因此,我使用while循环,并启用了步骤选项设置,将其值设置为True

while solver1.successful() and solver1.t < t0+dt:
    solver1.integrate(t_end,step=True)
    time.append(solver1.t)

我画出了y,这是积分结果,这里出现了问题。我发现不稳定性出现在一个特定区域:

启用求解器的步进选项的 y

我以为是因为循环或其他原因,所以我取消了step并检查了结果:

while solver1.successful() and solver1.t < t0+dt:
    solver1.integrate(t_end)

惊喜的是... 我得到了正确的结果:

禁用求解器的步骤选项

这是一个非常奇怪的情况... 如果你们中的任何人能帮助我解决这个问题,我将不胜感激。

编辑:

设置求解器的方式如下:

solver1 = ode(y_dot,jac).set_integrator('vode',with_jacobian=True)
solver1.set_initial_value(x0,t0)

我使用.append()存储结果。


您能展示更多代码吗?例如,您是如何设置求解器并存储结果以进行绘图的? - silvado
当然,我刚刚编辑了我的问题。 - kuider
你还没有展示出你是如何实际存储当前的ODE状态以进行绘图的,假设这些绘图显示了ODE状态变量之一。 - Nikolas
1个回答

2

当您设置 step=True 时,您间接地向 vode._integrator.runner(一个Fortran子例程)发出指令,要使用 itask=2,而默认值是 itask=1。您可以通过以下方式获取有关此 runner 的更多详细信息:

r._integrator.runner?

在SciPy 0.12.0文档中,您将找不到有关不同的itask=1itask=2发生了什么的解释,但是您可以在此处找到:链接
ITASK  = An index specifying the task to be performed.
!          Input only. ITASK has the following values and meanings.
!          1  means normal computation of output values of y(t) at
!             t = TOUT(by overshooting and interpolating).
!          2  means take one step only and return.
!          3  means stop at the first internal mesh point at or
!             beyond t = TOUT and return.
!          4  means normal computation of output values of y(t) at
!             t = TOUT but without overshooting t = TCRIT.
!             TCRIT must be input as RUSER(1). TCRIT may be equal to
!             or beyond TOUT, but not behind it in the direction of
!             integration. This option is useful if the problem
!             has a singularity at or beyond t = TCRIT.
!          5  means take one step, without passing TCRIT, and return.
!             TCRIT must be input as RUSER(1).

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接