私はPythonとscipyに比較的慣れておらず、MATLABからの変換です。scipy.integrate の odeint 関数の簡単なテストを行っていたところ、この潜在的なバグに遭遇しました。次のスニペットを検討してください。
from scipy import *
from scipy.integrate import odeint
from scipy.interpolate import interp1d
from pylab import *
# ODE system with forcing function u(t)
def sis(x,t,u):
return [x[1], u(t)]
# Solution time span
t = linspace(0, 10, 1e3)
# Profile for forcing function u(t)
acel = lambda t: 3*(t<2)-3*(t>8)
# Interpolator for acelerator
acel_interp = interp1d(t, acel(t), bounds_error=False, fill_value=0)
# ODE integration with u(t) = acel, a lambda function
x_1 = odeint(sis, [0,0], t, args=(acel,) ) # Correct result
# ODE integration with u(t) = acel_interp, an interpolator
x_2 = odeint(sis, [0,0], t, args=(acel_interp,) ) # Incorrect result
両方の結果の違いを示すプロットを作成しました。ここをクリックしてください。
少なくとも私にとっては、不当な結果の違いについてどう思いますか? Python 2.6.6 の上で NumPy バージョン 1.5.0 と SciPy バージョン 0.8.0 を使用しています