2012-10-07 59 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

相關問題