【发布时间】:2017-01-03 00:29:53
【问题描述】:
当我在scipy.integrate.odeint 中观察到意外行为时,我正在做一些模拟。
我可以用这段代码重现我的问题:
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
tau = 0.01
a, b = 0.7, 0.8
def E_p(t):
E = -0.07
if t < b and t > a:
E = -0.05
return E
def dynamics(V, t):
return (E_p(t) - V)/tau
time = np.arange(0, 1, 0.001)
ps = odeint(dynamics, -0.07, time)
plt.plot(time, ps)
当我将 a 和 b 设置为靠近左侧的间隔(在我的情况下为零)odeint 效果很好,而不是在右侧设置间隔时它什么也没有。
我希望看到这个
但更靠右。我真正想做的是在 RC 电路中模拟方脉冲。
我相信odeint在感觉功能已经收敛的时候就停止集成了,但是我找不到任何说明这个的文档。
【问题讨论】:
-
我不认为
odeint能够处理像你这样的不连续函数 -
嗯,我使用 a = 0.1 和 b = 0.2 制作了该图像,因此它适用于某些情况。很高兴知道它何时起作用,但我会假设它不起作用并使用另一个功能。将来我还需要处理一般的脉冲响应,所以我需要一个处理不连续函数的函数。