Skip to Content

HODGKIN_HUXLEY

Overview

The HODGKIN_HUXLEY function numerically solves the Hodgkin-Huxley system of ordinary differential equations for neuron action potentials, modeling the dynamics of membrane potential and gating variables for sodium and potassium channels. This classic model describes how action potentials in neurons are initiated and propagated, using four variables: membrane potential (V), sodium activation (m), sodium inactivation (h), and potassium activation (n). The ODE system is:

dVdt=IextINaIKILCmINa=gNam3h(VENa)IK=gKn4(VEK)IL=gL(VEL)\begin{align*} \frac{dV}{dt} &= \frac{I_{ext} - I_{Na} - I_{K} - I_{L}}{C_m} \\ I_{Na} &= g_{Na} m^3 h (V - E_{Na}) \\ I_{K} &= g_{K} n^4 (V - E_{K}) \\ I_{L} &= g_{L} (V - E_{L}) \end{align*}

where IextI_{ext} is the external current, CmC_m is membrane capacitance, gNag_{Na}, gKg_{K}, gLg_{L} are conductances, and ENaE_{Na}, EKE_{K}, ELE_{L} are reversal potentials. The function uses SciPy’s ODE solver (scipy.integrate.solve_ivp ) to integrate the system from t_start to t_end. Only the basic four-variable model is exposed; parameters for spatial extensions, temperature, or ion concentrations are not included. The integration method can be selected from several common solvers, but only the most used options are exposed. This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=HODGKIN_HUXLEY(v_initial, m_initial, h_initial, n_initial, i_ext, t_start, t_end, [timesteps], [solve_ivp_method])
  • v_initial (float, required): Initial membrane potential.
  • m_initial (float, required): Initial sodium activation variable.
  • h_initial (float, required): Initial sodium inactivation variable.
  • n_initial (float, required): Initial potassium activation variable.
  • i_ext (float, required): External current.
  • t_start (float, required): Start time for integration.
  • t_end (float, required): End time for integration.
  • timesteps (int, optional, default=10): Number of timesteps to solve for.
  • solve_ivp_method (string (enum), optional, default=‘RK45’): Integration method. Valid options: RK45, RK23, DOP853, Radau, BDF, LSODA.

The function returns a 2D array (table) with columns: t, V, m, h, n, representing time, membrane potential, and gating variables at each step. If the input is invalid or integration fails, a string error message is returned.

Examples

Example 1: Basic Case

Inputs:

v_initialm_initialh_initialn_initiali_extt_startt_endtimesteps
-65.00.050.60.3210.00.010.010

Excel formula:

=HODGKIN_HUXLEY(-65.0, 0.05, 0.6, 0.32, 10.0, 0.0, 10.0, 10)

Expected output:

tVmhn
0.000-65.0000.0500.6000.320
1.111-54.9600.1180.5750.335
2.22239.5300.9390.3270.535
3.333-11.5500.9680.1110.760
4.444-68.1300.2960.0900.742
5.556-74.5900.0160.1930.645
6.667-73.1700.0190.2810.566
7.778-71.3000.0240.3490.504
8.889-69.0900.0310.4000.458
10.000-66.7500.0410.4360.425

Example 2: With Optional Method (RK23)

Inputs:

v_initialm_initialh_initialn_initiali_extt_startt_endtimestepsmethod
-65.00.050.60.3210.00.010.010RK23

Excel formula:

=HODGKIN_HUXLEY(-65.0, 0.05, 0.6, 0.32, 10.0, 0.0, 10.0, 10, "RK23")

Expected output:

tVmhn
0.000-65.0000.0500.6000.320
1.111-54.9600.1180.5750.335
2.22239.6800.9380.3280.534
3.333-11.4100.9680.1110.760
4.444-68.1400.3000.0900.742
5.556-74.6000.0160.1930.645
6.667-73.1900.0190.2800.566
7.778-71.3200.0240.3490.504
8.889-69.1200.0310.4000.458
10.000-66.7700.0410.4360.425

Example 3: Longer Time Span

Inputs:

v_initialm_initialh_initialn_initiali_extt_startt_endtimesteps
-65.00.050.60.3210.00.050.010

Excel formula:

=HODGKIN_HUXLEY(-65.0, 0.05, 0.6, 0.32, 10.0, 0.0, 50.0, 10)

Expected output:

tVmhn
0.000-65.0000.0500.6000.320
5.556-74.5900.0160.1930.645
11.111-64.4600.0530.4580.404
16.667-29.8600.3670.3550.447
22.222-71.4400.0230.3290.508
27.778-60.4800.0840.4590.389
33.333-42.8100.7550.0690.750
38.889-67.3100.0380.4150.432
44.444-56.1500.1290.4350.400
50.000-73.8100.0180.2270.596

Example 4: Different Current

Inputs:

v_initialm_initialh_initialn_initiali_extt_startt_endtimesteps
-65.00.050.60.3215.00.010.010

Excel formula:

=HODGKIN_HUXLEY(-65.0, 0.05, 0.6, 0.32, 15.0, 0.0, 10.0, 10)

Expected output:

tVmhn
0.000-65.0000.0500.6000.320
1.111-46.9900.1810.5540.347
2.22224.0300.9940.2210.666
3.333-29.0900.8930.0830.773
4.444-74.5000.0420.1250.708
5.556-73.3400.0190.2220.618
6.667-71.3600.0230.2980.547
7.778-68.9100.0310.3560.493
8.889-66.2100.0430.3950.454
10.000-63.5200.0590.4190.430

Python Code

import math from scipy.integrate import solve_ivp import numpy as np def hodgkin_huxley(v_initial, m_initial, h_initial, n_initial, i_ext, t_start, t_end, timesteps=10, solve_ivp_method='RK45'): """ Numerically solves the Hodgkin-Huxley system of ordinary differential equations for neuron action potentials. Args: v_initial: Initial membrane potential. m_initial: Initial sodium activation variable. h_initial: Initial sodium inactivation variable. n_initial: Initial potassium activation variable. i_ext: External current. t_start: Start time of integration. t_end: End time of integration. timesteps: Number of timesteps to solve for. Default is 10. solve_ivp_method: Integration method ('RK45', 'RK23', 'DOP853', 'Radau', 'BDF', 'LSODA'). Default is 'RK45'. Returns: 2D list with header row: t, V, m, h, n. Each row contains time and variable values, or an error message (str) if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Validate inputs try: v0 = float(v_initial) m0 = float(m_initial) h0 = float(h_initial) n0 = float(n_initial) I_ext = float(i_ext) t0 = float(t_start) t1 = float(t_end) ntp = int(timesteps) except Exception: return "Invalid input: All initial values, parameters, and timesteps must be numbers." if t1 <= t0: return "Invalid input: t_end must be greater than t_start." if ntp <= 0: return "Invalid input: timesteps must be a positive integer." if solve_ivp_method not in ['RK45', 'RK23', 'DOP853', 'Radau', 'BDF', 'LSODA']: return "Invalid input: solve_ivp_method must be one of RK45, RK23, DOP853, Radau, BDF, LSODA." # Hodgkin-Huxley parameters C_m = 1.0 # uF/cm^2 g_Na = 120.0 # mS/cm^2 g_K = 36.0 # mS/cm^2 g_L = 0.3 # mS/cm^2 E_Na = 50.0 # mV E_K = -77.0 # mV E_L = -54.387 # mV # Rate functions def alpha_m(V): exp_val = math.exp(-(V + 40) / 10) if abs(1 - exp_val) < 1e-10: return 1.0 return 0.1 * (V + 40) / (1 - exp_val) def beta_m(V): return 4.0 * math.exp(-(V + 65) / 18) def alpha_h(V): return 0.07 * math.exp(-(V + 65) / 20) def beta_h(V): return 1 / (1 + math.exp(-(V + 35) / 10)) def alpha_n(V): exp_val = math.exp(-(V + 55) / 10) if abs(1 - exp_val) < 1e-10: return 0.1 return 0.01 * (V + 55) / (1 - exp_val) def beta_n(V): return 0.125 * math.exp(-(V + 65) / 80) # ODE system def hh_ode(t, y): V, m, h, n = y # Currents I_Na = g_Na * m**3 * h * (V - E_Na) I_K = g_K * n**4 * (V - E_K) I_L = g_L * (V - E_L) dVdt = (I_ext - I_Na - I_K - I_L) / C_m 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] # Time points t_eval = np.linspace(t0, t1, ntp) y0 = [v0, m0, h0, n0] try: sol = solve_ivp(hh_ode, [t0, t1], y0, method=solve_ivp_method, t_eval=t_eval, vectorized=False) if not sol.success: return f"ODE solver failed: {sol.message}" result = [[float(sol.t[i]), float(sol.y[0][i]), float(sol.y[1][i]), float(sol.y[2][i]), float(sol.y[3][i])] for i in range(len(sol.t))] # Add header row return [["t", "V", "m", "h", "n"]] + result except Exception as e: return f"ODE solver error: {e}"

Example Workbook

Link to Workbook 

Last updated on