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

时间:2013-03-20 13:05:56

标签: python scipy numerical-methods ode

当我调用它时,我想存储求解器本身采用的不同集成步骤:

solver1.integrate(t_end)

所以我做了一个while循环并启用了step选项,将其值设置为True

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

然后我绘制y,整合的结果,这就是我的问题。我有不稳定性出现在一个位置区域:

y enabling the step option of the solver

我认为这是因为循环或类似的东西,所以我检查了删除step的结果:

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

令人惊讶的是......我的结果是正确的:

y disabling the step option of the solver

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

编辑:

设置我做的求解器:

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

我使用.append()

存储结果

1 个答案:

答案 0 :(得分:2)

当你设置step=True时,你间接地给vode._integrator.runner(一个Fortran子程序)一个使用itask=2的指令,默认为itask=1。您可以获取有关此runner做的更多详细信息:

r._integrator.runner?

在SciPy 0.12.0文档中,您无法找到有关不同itask=1itask=2but you can find it here的内容的说明:

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).