如何绘制指数函数的cu

2024-05-14 15:36:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了下面的代码,但当我运行它时,它显示了一个线性图,而不是指数函数曲线。你知道吗

如果有人能告诉我哪里错了,我会感激你的帮助。 我希望在绘图时是指数曲线,而不是线性图。你知道吗


import numpy as np
import matplotlib.pyplot as plt

######### Constants
El      =   -0.70                   # resting membrane potential [V]
thresh  =   3                      # spiking threshold [V]


# VOLTAGE
T       =   100       # total simulation length [s]
dt      =   0.2       # step size [s]
time    =   np.arange(0, T+dt, dt) # time has 501 elements
V       =   np.zeros(len(time))         # array for saving Voltage history
V[0]    =   El
I = np.zeros(len(time))
I[100] = 1
counter=0
t_ref=5
tau=1.25
Weight=5

######### Simulation
def eps(s):
    return (s/tau)*np.exp(1-(s/tau))



for t in range(len(time)):

    spike_trains_window= I[:counter+1] #read I till counter says
    temp=0
    for i in range(len(spike_trains_window)):
        if spike_trains_window[i]==1: 
            s= t-i
            temp+=eps(s) #use an exponential function for computing temp
    V[t]= Weight*temp


    if V[t]> thresh:
        V[t-1]=3.5
        V[t] = El
        I= np.delete(I, np.s_[0:counter+t_ref], axis=0) #removing previous firing times+ incoming spikes in refractory period
        counter = 0
    else:
        counter+=1    


######### Plotting
fig = plt.figure()
line = plt.plot(V)
plt.show()


Tags: inforlentimenpcounterdtplt
1条回答
网友
1楼 · 发布于 2024-05-14 15:36:16

虽然我不完全理解您的代码应该做什么,但我看到了以下问题:

I中只有on值,它是非零的,所以这部分只有TRUE 一次:

if spike_trains_window[i]==1:
  s = t-i
  temp+=eps(s)

这将给V[t]V[t-1]分配一个非零值。因为这个值大于tresh,我们有V[t]=EL=-0.7V[t-1]=3.5,这正是我在图中得到的。你知道吗

所以我认为你的代码是工作的,没有错误,但可能它没有做你想做的事情,因为你没有让它做你想做的事情

相关问题 更多 >

    热门问题