I'm relatively new to python and scipy, being a convert from MATLAB. I was doing a quick test of the odeint function in scipy.integrate, and came across this potential bug. Consider the following snippet:
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
I have made a plot that illustrates the difference of both results, click here.
What do you make of this, at least for me, unwarranted difference in results? I'm using NumPy version 1.5.0 and SciPy version 0.8.0 on top of Python 2.6.6