我想在 Python 中实现一个简单的漏火积分器模型。这个想法是应用一个公式来计算一段时间内的电压 (u),并在达到某个时间时将电压重置为 0(在我的代码中,当 t 达到 t_btw_spikes 时)。这是我的代码:
# Leaky Integrator
def leaky_int(R, I_c, t, tau):
t_btw_spikes = tau*np.log((R*I_c)/R*I_c-v_th)
while t < t_btw_spikes:
u = (R*I_c*(1-np.exp(-t_array/tau)))
t +=0.001
else:
u = 0
这就是我如何调用这个函数
t = 0
R = 1
v_th = 15
t_array = np.linspace(0,0.1, 1000)
tau = 0.01 #s
I_c = 20
trial1 = leaky_int(R, I_c, t, tau)
plt.plot(t_array, trial1)
plt.xlabel('Time')
plt.ylabel('Voltage')
#check time btw spikes
t_btw_spikes = tau*np.log((R*I_c)/R*I_c-v_th)
print(t_btw_spikes)
问题是它返回给我 ValueError: x and y must not be None