【问题标题】:integrate.odeint gives two very different answers when it shouldn't在不应该的时候,integrate.odeint 给出了两个截然不同的答案
【发布时间】:2012-09-28 01:10:41
【问题描述】:

我有以下python MWE(代码解释如下)

#!/usr/bin/python
from scipy import integrate
from math import *
import numpy
import matplotlib.pyplot as plt

def base_equations(y,t,center):
    return [5*exp(-(t-center)**2/3),-5*exp(-(t-center)**2/3)]

def eqexec1(y,t):
    return base_equations(y,t,30)

def eqexec2(y,t):
    return base_equations(y,t,60)

inits=[0.5, 0.5]

trange=numpy.arange(0,100,0.1)
print trange

y1=integrate.odeint(eqexec1,inits, trange, full_output=0, printmessg=1)
y2=integrate.odeint(eqexec2,inits, trange, full_output=0, printmessg=1)
plt.plot(trange,y1,trange,y2)
plt.legend(["y1a","y1b","y2a","y2b"])
plt.xlabel("Time")
plt.show()

如您所见,我正在整合一组方程 (base_equations),它们本质上是一个高斯脉冲。我使用odeint 为脉冲的两个中心点(30 和 60)数值求解这些方程。

对于第一个中心点 (t=30),方程 y1 产生预期的行为:脉冲是可见的。

对于第二个中心点 (t=60),方程 y2 产生了意想不到的行为:根本看不到任何脉冲!

工作和不工作之间的切换发生在47和48之间。

图形输出如下。预期的输出是 y2a 和 y2b 行将在 60 左右显示出巨大的变化,但事实并非如此。

对可能发生的事情有什么想法吗?

【问题讨论】:

    标签: python scipy ode


    【解决方案1】:

    积分器在衍生物消失的初始区域中增加了其阶梯尺寸,并且步骤变得如此之大,即它在高斯峰值上面从未看到过。

    您可以告诉Integrator不增加阶梯尺寸太多:

    y2 = integrate.odeint(eqexec2,inits, trange, full_output=0, printmessg=1,hmax=1.0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-02
      • 1970-01-01
      • 2011-01-19
      • 2019-09-19
      相关资源
      最近更新 更多