From Equations to Code
Neuroscience talks in differential equations. Calculus textbooks are full of them. But you can't run calculus on a computer β calculus is continuous, computers work with discrete time steps.
So how do you simulate a neuron? You approximate. You take tiny time steps (dt = 0.001 seconds) and update the voltage in small chunks.
# Differential equation (continuous time):
# dV/dt = (-(V - V_rest) + R*I) / tau_m
#
# This says: the voltage changes at a rate proportional to the difference between current and rest potential.
# Approximation (discrete time, Euler method):
# V_new = V_old + (dV/dt) * dt
#
# In code:
for t in range(1000): # loop over time
# Compute the rate of change
dV_dt = (-(V[t] - V_rest) + R * I[t]) / tau_m
# Take one small step
V[t+1] = V[t] + dV_dt * dt
# If crossed threshold, record spike and reset
if V[t+1] > threshold:
spikes.append(t+1)
V[t+1] = V_restThis is the skeleton of EVERY neuron simulation in NMA. You'll write variations of this hundreds of times.
Why Euler's method?
It's the simplest: V_new = V_old + slope * dt. You step forward in time, updating based on the current slope. Smaller dt = more accurate. Typical choice: dt = 0.0001 to 0.001 seconds.
NMA fact: Week 2-3 is all about this. You'll implement LIF, Hodgkin-Huxley, and other models. All of them use Euler's method or a variant.