Electrical Circuit Model of the Plasma Membrane
A comprehensive guide to understanding the cell membrane as an electrical circuit, featuring interactive simulations, mathematical derivations, and Python code.
Learning Objectives
- โขModel the plasma membrane as a parallel RC circuit with ion-specific conductances
- โขDerive the Thรฉvenin equivalent circuit and understand its physical meaning
- โขApply Kirchhoff's laws to calculate membrane potential and ionic currents
- โขUnderstand the Hodgkin-Huxley model and its Nobel Prize-winning implications
- โขImplement numerical simulations of action potentials using Python
โกInteractive Membrane Circuit Diagram
Channel Conductances
E_Na = +61 mV โข I = -145.72 ยตA/cmยฒ
E_K = -89 mV โข I = 154.05 ยตA/cmยฒ
E_Cl = -70 mV โข I = -4.42 ยตA/cmยฒ
E_Leak = -70 mV โข I = -4.42 ยตA/cmยฒ
Calculated Values
Thรฉvenin Equivalent Circuit Derivation
The complex membrane circuit with multiple ion channels can be simplified to a single voltage source (Vth) in series with a single resistance (Rth). This Thรฉvenin equivalent captures the essential electrical behavior of the membrane.
Step-by-Step Derivation
Step 1: Apply Kirchhoff's Current Law
At steady state, all ionic currents sum to zero:
Step 2: Express Each Current Using Ohm's Law
Step 3: Substitute and Solve for $V_m$
Collecting terms:
Step 4: Final Thรฉvenin Voltage
This is the Goldman-Hodgkin-Katz equation!
Step 5: Thรฉvenin Resistance
Numerical Example: Resting Neuron
Given Values (typical neuron)
g_total = 1 + 36 + 0.3 + 0.3 = 37.6 mS/cmยฒ
V_th = (1ร61 + 36ร(-89) + 0.3ร(-70) + 0.3ร(-70)) / 37.6
V_th = (61 - 3204 - 21 - 21) / 37.6
V_th = -84.7 mV
R_th = 1000/37.6 = 26.6 ฮฉยทcmยฒ
Physical Interpretation
The resting potential (-70 mV) is close to E_K (-89 mV) because Kโบ conductance dominates at rest (36 out of 37.6 mS/cmยฒ). The small Naโบ conductance pulls V_m slightly positive from E_K.
Circuit Schematic Representations
Full Membrane Circuit
EXTRACELLULAR (0 mV reference)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ โ โ
โ โโดโ โโดโ โโดโ โโดโ
โโผโ โ โ โ โ โ โ โ โ
โโโผโโ โ โgNa โ โgK โ โgCl โ โgLeak
โโผโ โ โ โ โ โ โ โ โ
โ โโฌโ โโฌโ โโฌโ โโฌโ
โ Cm โ โ โ โ
โ โ โ โ โ
โ โโโดโโ โโโดโโ โโโดโโ โโโดโโ
โ +โ โ- -โ โ+ -โ โ+ -โ โ+
โ โ E โ โ E โ โ E โ โ E โ
โ โNa โ โ K โ โCl โ โ L โ
โ โ+61โ โ-89โ โ-70โ โ-70โ
โ โโโฌโโ โโโฌโโ โโโฌโโ โโโฌโโ
โ โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
INTRACELLULAR (Vm โ -70 mV)
Cm = Membrane Capacitor (1 ยตF/cmยฒ)
gX = Ion Channel Conductance (variable resistor)
EX = Nernst Equilibrium Potential (battery/EMF)Thรฉvenin Equivalent
EXTRACELLULAR (0 mV)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ
โโดโ
โ โ Rth = 1/gtotal
โ โ = 26.6 ฮฉยทcmยฒ
โ โ
โโฌโ
โ
โโโดโโ
+โ โ-
โVthโ Vth = ฮฃgiEi/ฮฃgi
โ โ = -70 mV
โโโฌโโ
โ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
INTRACELLULAR (Vm)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Time Constant: โ
โ ฯ = Rth ร Cm โ
โ = 26.6 ร 1 ยตF โ
โ = 26.6 ms โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโComplete Circuit with Naโบ/Kโบ-ATPase Pump
EXTRACELLULAR
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ โ โ โ
โ โโดโ โโดโ โโดโ โโดโ โ
โโผโ โ โ โ โ โ โ โ โ โโโโดโโโ
โโโผโโ โ โgNa โ โgK โ โgCl โ โgL โPUMP โ 3Naโบ OUT
โโผโ โ โ โ โ โ โ โ โ โ โโโโโโโโบ
โ โโฌโ โโฌโ โโฌโ โโฌโ โ ATP โ
โ Cm โ โ โ โ โ โ 2Kโบ IN
โ โ โ โ โ โ โโโโโโโโ
โ โโโดโโ โโโดโโ โโโดโโ โโโดโโ โโโโฌโโโ
โ +โ โ- -โ โ+ -โ โ+ -โ โ+ โ
โ โENaโ โ EKโ โEClโ โ ELโ โโผโ Current
โ โ+61โ โ-89โ โ-70โ โ-70โ โโโผโโ Source
โ โโโฌโโ โโโฌโโ โโโฌโโ โโโฌโโ โโผโ (Ipump)
โ โ โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
INTRACELLULAR (Vm)
Naโบ/Kโบ-ATPase: Electrogenic pump that maintains ion gradients
โข Exports 3 Naโบ ions โ Creates outward current
โข Imports 2 Kโบ ions โ Net charge movement = hyperpolarizing
โข Ipump โ 0.5-1.0 ยตA/cmยฒ (contributes ~5 mV to resting potential)Action Potential Waveform & Conductance Changes
Vm (mV)
+40 โค โญโโฎ
โ โฑ โฒ
+20 โค โฑ โฒ
โ โฑ โฒ
0 โค โฑ โฒ
โ โฑ โฒ
-20 โค โฑ โฒ
โ โฑ โฒ
-40 โค โฑ โฒ
โ โฑ โฒ
-55 โคโ โ โ โ โโฑโThresholdโ โ โ โ โ โโฒโ โ โ โ โ โ โ โ โ
โ โฑ โฒ
-70 โผโโโโโโโโฑ โฒโโโโโโโโโโโโโโโโโ Resting
โ โ โฒ_____โฑ
-90 โค Stimulus Undershoot (AHP)
โโโโโโดโโโโโดโโโโโดโโโโโดโโโโโดโโโโโดโโโโโดโโโโโดโโโโโดโโโโโบ Time (ms)
0 1 2 3 4 5 6 7 8
Conductances:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
gNa โโโโโโฎ (Fast activation, fast inactivation)
(red) โโโโโโ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
gK โโโโโโโโโโโโโโโโฎ (Slow activation, no inactivation)
(green) โโโโโโโโโ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
PHASES:
1. REST: gK >> gNa โ Vm near EK (-89 mV), but modified by other channels
2. RISING: gNa >> gK โ Vm rushes toward ENa (+61 mV)
3. PEAK: Naโบ inactivation begins (h gate closes)
4. FALLING: gK increases, gNa decreases โ Vm returns toward EK
5. UNDERSHOOT: gK still elevated โ Vm briefly more negative than restConductance State Comparison
โ Resting State
gK dominates โ Vm โ โ70 mV
gNa โโโโโโโโโโโโโโโโโโโโ 1 mS/cmยฒ gK โโโโโโโโโโโโโโโโโโโโ 36 mS/cmยฒ gCl โโโโโโโโโโโโโโโโโโโโ 0.3 mS/cmยฒ
Vm = (1ร61 + 36ร(โ89) + 0.3ร(โ70)) / 37.3 โ โ70 mV
โก Depolarized (AP Peak)
gNa dominates โ Vm โ +40 mV
gNa โโโโโโโโโโโโโโโโโโโโ 120 mS/cmยฒ gK โโโโโโโโโโโโโโโโโโโโ 36 mS/cmยฒ gCl โโโโโโโโโโโโโโโโโโโโ 0.3 mS/cmยฒ
Vm = (120ร61 + 36ร(โ89)) / 156 โ +26 mV
โข Repolarizing (AHP)
gK elevated โ Vm โ โ89 mV
gNa โโโโโโโโโโโโโโโโโโโโ ~0 mS/cmยฒ gK โโโโโโโโโโโโโโโโโโโโ 72 mS/cmยฒ gCl โโโโโโโโโโโโโโโโโโโโ 0.3 mS/cmยฒ
Vm โ EK = โ89 mV (undershoot)
Complete Circuit Theory
Batteries (E_ion)
Each ion's Nernst potential acts as an EMF source. The "battery" drives ions toward equilibrium.
E_Na = +61 mV (pulls positive)
E_K = -89 mV (pulls negative)
Resistors (g_ion)
Conductance (g = 1/R) represents how easily ions flow. Higher g means more current.
g_K at rest โ 36 mS/cmยฒ
g_Na at rest โ 1 mS/cmยฒ
Capacitor (C_m)
The lipid bilayer acts as a dielectric, storing charge and slowing voltage changes.
C_m โ 1 ยตF/cmยฒ
d โ 7-8 nm thickness
Current Source (Pump)
The Naโบ/Kโบ-ATPase is an electrogenic pump, contributing a small outward current.
3 Naโบ out / 2 Kโบ in
Contributes ~-10 mV
Key Equations
Nernst Equation
At 37ยฐC: $E_X = \frac{61.5}{z} \log_{10} \frac{[X]_o}{[X]_i}$ mV
Ohm's Law for Ion Channels
Current flows when $V_m \neq E_{\text{ion}}$ (driving force exists)
Kirchhoff's Current Law
At steady state: $I_{\text{Na}} + I_{\text{K}} + I_{\text{Cl}} + I_{\text{Leak}} = 0$
Goldman-Hodgkin-Katz Equation
Weighted average of equilibrium potentials, weighted by conductances
RC Time Constant
$\tau \approx 2\text{-}5$ ms for neurons. Time for $V_m$ to reach 63% of final value.
Membrane Capacitor Equation
Capacitive current only flows during voltage changes
Hodgkin-Huxley Gating Variables
The Nobel Prize-winning Hodgkin-Huxley model (1952) introduced voltage-dependent gating variables that describe how ion channel conductances change during an action potential.
Naโบ Channel
m: activation gate (fast)
h: inactivation gate (slow)
Kโบ Channel
n: activation gate (slow)
Delayed rectifier current
Gating Kinetics
$\alpha$ and $\beta$ are voltage-dependent rate constants
Complete Hodgkin-Huxley Equation
Experimental Measurement Techniques
Voltage Clamp
Developed by Cole (1949) and perfected by Hodgkin & Huxley (1952). The technique uses negative feedback to hold V_m constant while measuring the current required.
- โข Measures ionic currents at fixed potentials
- โข Separates Naโบ and Kโบ currents pharmacologically
- โข Used to determine g-V relationships
Patch Clamp
Invented by Neher & Sakmann (1976, Nobel Prize 1991). Records currents through individual ion channels with pA resolution.
- โข Cell-attached, whole-cell, inside-out, outside-out
- โข Single channel conductances: 10-50 pS typical
- โข Reveals channel gating kinetics
Nobel Prize Recognition
โข 1963: Hodgkin & Huxley (ionic mechanisms of action potentials)
โข 1991: Neher & Sakmann (patch clamp technique)
Key Circuit Insights
The Weighted Average Principle
The plasma membrane circuit reveals that the resting potential (โ70 mV) is simply a weighted average of all open ion pathways:
Naโบ at +61 mV
Pulls membrane positive (depolarizing). Opening Naโบ channels shifts V_m toward +61 mV.
Kโบ at โ89 mV
Pulls membrane negative (hyperpolarizing). Kโบ dominates at rest because g_K >> g_Na.
Demystifying the Action Potential
The action potential requires no mystical propertiesโjust parallel resistors and batteries!
- 1Depolarization: Voltage-gated Naโบ channels open, increasing g_Na from 1 to ~120 mS/cmยฒ. V_m shifts from โ70 toward +61 mV.
- 2Peak: V_m reaches ~+40 mV (not quite E_Na because g_K is still present). Naโบ channels begin inactivating (h โ 0).
- 3Repolarization: Kโบ channels open (delayed), increasing g_K. V_m returns toward โ89 mV as Kโบ conductance dominates.
- 4Afterhyperpolarization: Kโบ channels remain open briefly, pushing V_m below resting (โ80 to โ90 mV) before returning to rest.
"Opening more Naโบ channels repels the potential away from E_K toward E_Na. This beautifully explains action potential generation without invoking any mystical propertiesโjust parallel resistors and batteries!"
Video Lectures
Comprehensive video series covering membrane electrophysiology, circuit models, and the Hodgkin-Huxley framework.
Featured: Hodgkin-Huxley Model Explained
Electrophysiology Basics

Nernst Equation And The Electrochemical Gradient Explained

Goldman Equation And The Resting Membrane Potential Explained

Neuron As RC Circuit Explained And Analysis of the Time Constant Tau

Cable Theory Model of the Neuron And Analysis Of The Space Constant Lambda

Equivalent Circuit Model Of The Neuron Explained (Capacitance, Resistance, Driving force)

Voltage Clamp Explained (Tetrodotoxin And Tetraethylammonium)

Action Potential Propagation And The Refractory Period Explained

Myelin And Axon Diameter Effect On Action Potential Conduction Velocity

Patch Clamp Explained (Cell-Attached, Whole Cell, Inside Out, Outside Out)

Hodgkin-Huxley Model of Voltage-Gated Channels Explained (Gating Variables n, m, h)

Python Simulation Of The Hodgkin-Huxley Model
MIT 9.40: Introduction to Neural Computation
Complete 20-lecture course covering biophysics to neural networks
Lecture 4: Hodgkin-Huxley Model Part 1

MIT 1: Course Overview and Ionic Currents

MIT 2: Resistor Capacitor Circuit and Nernst Potential

MIT 3: Resistor Capacitor Neuron Model

MIT 4: Hodgkin-Huxley Model Part 1

MIT 5: Hodgkin-Huxley Model Part 2

MIT 6: Dendrites

MIT 7: Synapses

MIT 8: Spike Trains

MIT 9: Receptive Fields

MIT 10: Time Series

MIT 11: Spectral Analysis Part 1

MIT 12: Spectral Analysis Part 2

MIT 13: Spectral Analysis Part 3

MIT 14: Rate Models and Perceptrons

MIT 15: Matrix Operations

MIT 16: Basis Sets

MIT 17: Principal Components Analysis

MIT 18: Recurrent Networks

MIT 19: Neural Integrators

MIT 20: Hopfield Networks
Simulation Code
Run simulations directly in your browser using Pyodide (Python in WebAssembly), or download to run locally.
Simple Membrane Potential Calculator
Calculate membrane potential using the parallel conductance model. Click 'Run in Browser' to execute.
# Simple Membrane Potential Calculator
# Using the parallel conductance model
import numpy as np
def calculate_membrane_potential(conductances, potentials, I_pump=0):
"""
Calculate membrane potential using the Goldman-Hodgkin-Katz equation.
Parameters:
-----------
conductances : dict
Dictionary of ion conductances in mS/cmยฒ
e.g., {'Na': 1, 'K': 36, 'Cl': 0.3, 'Leak': 0.3}
potentials : dict
Dictionary of equilibrium potentials in mV
e.g., {'Na': 61, 'K': -89, 'Cl': -70, 'Leak': -70}
I_pump : float
Pump current in ยตA/cmยฒ (default 0)
Returns:
--------
dict : Contains Vm, Rth, tau, and individual currents
"""
# Calculate total conductance
g_total = sum(conductances.values())
# Calculate membrane potential (weighted average)
numerator = sum(conductances[ion] * potentials[ion]
for ion in conductances) - I_pump
Vm = numerator / g_total
# Calculate individual currents
currents = {ion: conductances[ion] * (Vm - potentials[ion])
for ion in conductances}
# Thรฉvenin equivalent
Rth = 1000 / g_total # ฮฉยทcmยฒ
# Time constant (assuming Cm = 1 ยตF/cmยฒ)
Cm = 1.0
tau = Cm * Rth / 1000 # ms
return {
'Vm': Vm,
'g_total': g_total,
'Rth': Rth,
'tau': tau,
'currents': currents
}
# Example: Resting neuron
conductances = {'Na': 1, 'K': 36, 'Cl': 0.3, 'Leak': 0.3}
potentials = {'Na': 61, 'K': -89, 'Cl': -70, 'Leak': -70}
result = calculate_membrane_potential(conductances, potentials)
print("=== Resting Membrane Analysis ===")
print(f"Membrane Potential: {result['Vm']:.2f} mV")
print(f"Total Conductance: {result['g_total']:.2f} mS/cmยฒ")
print(f"Thรฉvenin Resistance: {result['Rth']:.2f} ฮฉยทcmยฒ")
print(f"Time Constant: {result['tau']:.2f} ms")
print("\nIndividual Currents (ยตA/cmยฒ):")
for ion, current in result['currents'].items():
print(f" I_{ion}: {current:.3f}")
# Example: Action potential peak (high Na+ conductance)
print("\n=== Action Potential Peak ===")
conductances_ap = {'Na': 120, 'K': 36, 'Cl': 0.3, 'Leak': 0.3}
result_ap = calculate_membrane_potential(conductances_ap, potentials)
print(f"Membrane Potential: {result_ap['Vm']:.2f} mV")Complete Hodgkin-Huxley Simulation
Full implementation with RK4 integration and gating kinetics. Runs in browser without matplotlib plotting.
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
# Hodgkin-Huxley Model Parameters (Giant Squid Axon)
C_m = 1.0 # Membrane capacitance (ยตF/cmยฒ)
g_Na_max = 120.0 # Max Na+ conductance (mS/cmยฒ)
g_K_max = 36.0 # Max K+ conductance (mS/cmยฒ)
g_L = 0.3 # Leak conductance (mS/cmยฒ)
E_Na = 50.0 # Na+ reversal potential (mV)
E_K = -77.0 # K+ reversal potential (mV)
E_L = -54.4 # Leak reversal potential (mV)
# Rate constants (alpha and beta functions)
def alpha_m(V): return 0.1 * (V + 40) / (1 - np.exp(-(V + 40) / 10))
def beta_m(V): return 4.0 * np.exp(-(V + 65) / 18)
def alpha_h(V): return 0.07 * np.exp(-(V + 65) / 20)
def beta_h(V): return 1.0 / (1 + np.exp(-(V + 35) / 10))
def alpha_n(V): return 0.01 * (V + 55) / (1 - np.exp(-(V + 55) / 10))
def beta_n(V): return 0.125 * np.exp(-(V + 65) / 80)
# Hodgkin-Huxley differential equations
def hodgkin_huxley(y, t, I_ext):
V, m, h, n = y
# Ionic currents
I_Na = g_Na_max * m**3 * h * (V - E_Na)
I_K = g_K_max * n**4 * (V - E_K)
I_L = g_L * (V - E_L)
# Membrane potential derivative
dVdt = (I_ext - I_Na - I_K - I_L) / C_m
# Gating variable derivatives
dmdt = alpha_m(V) * (1 - m) - beta_m(V) * m
dhdt = alpha_h(V) * (1 - h) - beta_h(V) * h
dndt = alpha_n(V) * (1 - n) - beta_n(V) * n
return [dVdt, dmdt, dhdt, dndt]
# Simulation parameters
T = 50.0 # Total time (ms)
dt = 0.01 # Time step (ms)
t = np.arange(0, T, dt)
# Initial conditions (resting state)
V0 = -65.0 # Resting potential (mV)
m0 = alpha_m(V0) / (alpha_m(V0) + beta_m(V0))
h0 = alpha_h(V0) / (alpha_h(V0) + beta_h(V0))
n0 = alpha_n(V0) / (alpha_n(V0) + beta_n(V0))
y0 = [V0, m0, h0, n0]
# External current stimulus
def I_stim(t):
return 10.0 if 10 < t < 40 else 0 # 10 ยตA/cmยฒ from t=10-40 ms
# Solve using RK4 (via odeint)
I_ext_array = [I_stim(ti) for ti in t]
solution = odeint(lambda y, ti: hodgkin_huxley(y, ti, I_stim(ti)), y0, t)
# Extract results
V = solution[:, 0]
m = solution[:, 1]
h = solution[:, 2]
n = solution[:, 3]
# Calculate conductances
g_Na = g_Na_max * m**3 * h
g_K = g_K_max * n**4
# Plot results
fig, axes = plt.subplots(3, 1, figsize=(10, 8), sharex=True)
axes[0].plot(t, V, 'b-', linewidth=1)
axes[0].set_ylabel('V_m (mV)')
axes[0].set_title('Hodgkin-Huxley Action Potential Simulation')
axes[0].axhline(-65, color='gray', linestyle='--', alpha=0.5)
axes[1].plot(t, m, 'r-', label='m (Na activation)')
axes[1].plot(t, h, 'r--', label='h (Na inactivation)')
axes[1].plot(t, n, 'g-', label='n (K activation)')
axes[1].set_ylabel('Gating variables')
axes[1].legend()
axes[2].plot(t, g_Na, 'r-', label='g_Na')
axes[2].plot(t, g_K, 'g-', label='g_K')
axes[2].set_xlabel('Time (ms)')
axes[2].set_ylabel('Conductance (mS/cmยฒ)')
axes[2].legend()
plt.tight_layout()
plt.savefig('hodgkin_huxley_simulation.png', dpi=150)
plt.show()Fortran 90 Implementation (High Performance)
For large-scale neural network simulations. Download and compile locally with gfortran.
! Hodgkin-Huxley Model in Fortran 90
! Simulates action potential propagation in squid giant axon
! Author: Cell Physiology Course
! Compile: gfortran -O3 -o hh hodgkin_huxley.f90
program hodgkin_huxley
implicit none
! Physical constants (double precision for accuracy)
real(8), parameter :: C_m = 1.0d0 ! Membrane capacitance (ยตF/cmยฒ)
real(8), parameter :: g_Na_max = 120.0d0 ! Max Na+ conductance (mS/cmยฒ)
real(8), parameter :: g_K_max = 36.0d0 ! Max K+ conductance (mS/cmยฒ)
real(8), parameter :: g_L = 0.3d0 ! Leak conductance (mS/cmยฒ)
real(8), parameter :: E_Na = 50.0d0 ! Na+ reversal potential (mV)
real(8), parameter :: E_K = -77.0d0 ! K+ reversal potential (mV)
real(8), parameter :: E_L = -54.4d0 ! Leak reversal potential (mV)
! Simulation parameters
real(8), parameter :: dt = 0.01d0 ! Time step (ms)
real(8), parameter :: T_max = 50.0d0 ! Total simulation time (ms)
integer, parameter :: N_steps = nint(T_max / dt)
! State variables
real(8) :: V, m, h, n
real(8) :: I_Na, I_K, I_L, I_ext
real(8) :: g_Na, g_K
real(8) :: t
! RK4 intermediate variables
real(8) :: k1_V, k2_V, k3_V, k4_V
real(8) :: k1_m, k2_m, k3_m, k4_m
real(8) :: k1_h, k2_h, k3_h, k4_h
real(8) :: k1_n, k2_n, k3_n, k4_n
real(8) :: V_tmp, m_tmp, h_tmp, n_tmp
integer :: i, output_unit
! Initialize at resting state
V = -65.0d0
m = alpha_m(V) / (alpha_m(V) + beta_m(V))
h = alpha_h(V) / (alpha_h(V) + beta_h(V))
n = alpha_n(V) / (alpha_n(V) + beta_n(V))
! Open output file
output_unit = 10
open(unit=output_unit, file='hh_output.dat', status='replace')
write(output_unit, '(A)') '# t(ms) V(mV) m h n g_Na g_K I_Na I_K'
! Main simulation loop using 4th-order Runge-Kutta
do i = 0, N_steps
t = i * dt
if (t > 10.0d0 .and. t < 40.0d0) then
I_ext = 10.0d0
else
I_ext = 0.0d0
end if
g_Na = g_Na_max * m**3 * h
g_K = g_K_max * n**4
I_Na = g_Na * (V - E_Na)
I_K = g_K * (V - E_K)
I_L = g_L * (V - E_L)
if (mod(i, 10) == 0) then
write(output_unit, '(9F12.4)') t, V, m, h, n, g_Na, g_K, I_Na, I_K
end if
! RK4 integration
k1_V = dVdt(V, m, h, n, I_ext)
k1_m = dmdt(V, m); k1_h = dhdt(V, h); k1_n = dndt(V, n)
V_tmp = V + 0.5d0*dt*k1_V
m_tmp = m + 0.5d0*dt*k1_m
h_tmp = h + 0.5d0*dt*k1_h
n_tmp = n + 0.5d0*dt*k1_n
k2_V = dVdt(V_tmp, m_tmp, h_tmp, n_tmp, I_ext)
k2_m = dmdt(V_tmp, m_tmp); k2_h = dhdt(V_tmp, h_tmp); k2_n = dndt(V_tmp, n_tmp)
V_tmp = V + 0.5d0*dt*k2_V
m_tmp = m + 0.5d0*dt*k2_m
h_tmp = h + 0.5d0*dt*k2_h
n_tmp = n + 0.5d0*dt*k2_n
k3_V = dVdt(V_tmp, m_tmp, h_tmp, n_tmp, I_ext)
k3_m = dmdt(V_tmp, m_tmp); k3_h = dhdt(V_tmp, h_tmp); k3_n = dndt(V_tmp, n_tmp)
V_tmp = V + dt*k3_V
m_tmp = m + dt*k3_m
h_tmp = h + dt*k3_h
n_tmp = n + dt*k3_n
k4_V = dVdt(V_tmp, m_tmp, h_tmp, n_tmp, I_ext)
k4_m = dmdt(V_tmp, m_tmp); k4_h = dhdt(V_tmp, h_tmp); k4_n = dndt(V_tmp, n_tmp)
V = V + (dt/6.0d0) * (k1_V + 2.0d0*k2_V + 2.0d0*k3_V + k4_V)
m = m + (dt/6.0d0) * (k1_m + 2.0d0*k2_m + 2.0d0*k3_m + k4_m)
h = h + (dt/6.0d0) * (k1_h + 2.0d0*k2_h + 2.0d0*k3_h + k4_h)
n = n + (dt/6.0d0) * (k1_n + 2.0d0*k2_n + 2.0d0*k3_n + k4_n)
m = max(0.0d0, min(1.0d0, m))
h = max(0.0d0, min(1.0d0, h))
n = max(0.0d0, min(1.0d0, n))
end do
close(output_unit)
print *, 'Simulation complete. Output saved to hh_output.dat'
contains
real(8) function alpha_m(V)
real(8), intent(in) :: V
real(8) :: x
x = V + 40.0d0
if (abs(x) < 1.0d-6) then
alpha_m = 1.0d0
else
alpha_m = 0.1d0 * x / (1.0d0 - exp(-x/10.0d0))
end if
end function
real(8) function beta_m(V)
real(8), intent(in) :: V
beta_m = 4.0d0 * exp(-(V + 65.0d0) / 18.0d0)
end function
real(8) function alpha_h(V)
real(8), intent(in) :: V
alpha_h = 0.07d0 * exp(-(V + 65.0d0) / 20.0d0)
end function
real(8) function beta_h(V)
real(8), intent(in) :: V
beta_h = 1.0d0 / (1.0d0 + exp(-(V + 35.0d0) / 10.0d0))
end function
real(8) function alpha_n(V)
real(8), intent(in) :: V
real(8) :: x
x = V + 55.0d0
if (abs(x) < 1.0d-6) then
alpha_n = 0.1d0
else
alpha_n = 0.01d0 * x / (1.0d0 - exp(-x/10.0d0))
end if
end function
real(8) function beta_n(V)
real(8), intent(in) :: V
beta_n = 0.125d0 * exp(-(V + 65.0d0) / 80.0d0)
end function
real(8) function dVdt(V, m, h, n, I_ext)
real(8), intent(in) :: V, m, h, n, I_ext
real(8) :: I_Na, I_K, I_L
I_Na = g_Na_max * m**3 * h * (V - E_Na)
I_K = g_K_max * n**4 * (V - E_K)
I_L = g_L * (V - E_L)
dVdt = (I_ext - I_Na - I_K - I_L) / C_m
end function
real(8) function dmdt(V, m)
real(8), intent(in) :: V, m
dmdt = alpha_m(V) * (1.0d0 - m) - beta_m(V) * m
end function
real(8) function dhdt(V, h)
real(8), intent(in) :: V, h
dhdt = alpha_h(V) * (1.0d0 - h) - beta_h(V) * h
end function
real(8) function dndt(V, n)
real(8), intent(in) :: V, n
dndt = alpha_n(V) * (1.0d0 - n) - beta_n(V) * n
end function
end program hodgkin_huxleyTo run Fortran: Download the file and compile with:
gfortran -O3 -o hh hodgkin_huxley.f90 && ./hhValidation Checklist for Debugging
Physical Checks
- โ Resting V_m between -60 and -80 mV
- โ AP peak near +40 mV (not exceeding E_Na)
- โ AP duration 1-2 ms (squid axon)
- โ Refractory period ~1-2 ms
- โ Currents sum to zero at steady state
Numerical Checks
- โ dt โค 0.01 ms for stability
- โ Gating variables remain in [0, 1]
- โ No NaN or Inf values
- โ Energy conservation (current balance)
- โ Compare with literature values
References & Further Reading
- โข Hodgkin AL, Huxley AF (1952). A quantitative description of membrane current and its application to conduction and excitation in nerve. J Physiol 117:500-544.
- โข Hille B (2001). Ion Channels of Excitable Membranes, 3rd ed. Sinauer Associates.
- โข Johnston D, Wu SM (1995). Foundations of Cellular Neurophysiology. MIT Press.
- โข Kandel ER et al. (2021). Principles of Neural Science, 6th ed. McGraw-Hill.
- โข Cole KS (1949). Dynamic electrical characteristics of the squid axon membrane. Arch Sci Physiol 3:253-258.