812.252.159 / 812_252_159.py
antitheft159's picture
Update 812_252_159.py
4713bcb verified
raw
history blame contribute delete
842 Bytes
import numpy as np
import matplotlib.pyplot as plt
# Parameters
tau_m = 20 # Membrane time constant (ms)
R_m = 1 # Membrane resistance (MΩ)
V_rest = -65 # Resting membrane potential (mV)
V_th = -50 # Spike threshold (mV)
V_reset = -65 # Reset potential (mV)
I = 1.5 # Input current (nA)
dt = 0.1 # Time step (ms)
t = np.arange(0, 100, dt) # Time vector
# Initialize membrane potential
V_m = np.zeros(len(t))
V_m[0] = V_rest
# Simulate the neuron
for i in range(1, len(t)):
dV = (-(V_m[i-1] - V_rest) + R_m * I) / tau_m
V_m[i] = V_m[i-1] + dV * dt
# Check for spike
if V_m[i] >= V_th:
V_m[i] = 20 # Spike to 20 mV
V_m[i+1] = V_reset # Reset potential
# Plot the results
plt.plot(t, V_m)
plt.title('.159 Neuron Simulation')
plt.xlabel('Time (ms)')
plt.ylabel('Membrane Potential (mV)')
plt.show()