2012-10-07 45 views
0

我有以下的Python MWE(代码如下解释)integrate.odeint给出了两个非常不同的答案时,它不应该

#!/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左右显示出巨大的变化,但它们不会。

Image showing a single Gaussian pulse when there should be two.

任何想法,以什么可能是怎么回事?

回答

3

积分器在导数消失的初始区域中增加其步长,并且步长变得非常大以至于它跨越高斯峰值而从不会看到它。

你可以告诉积分不增加步长太多:

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

拍摄!当你这么说的时候似乎很明显...... – Richard

相关问题