Skip to Content

FITZHUGH_NAGUMO

Overview

The FITZHUGH_NAGUMO function numerically solves the FitzHugh-Nagumo system of ordinary differential equations, modeling neuron action potentials with two variables: membrane potential and recovery variable. This model is a simplification of the Hodgkin-Huxley model and is widely used in computational neuroscience to study excitability and oscillations in neurons. The ODE system is:

dvdt=vv33w+Iextdwdt=v+abwτ\begin{align*} \frac{dv}{dt} &= v - \frac{v^3}{3} - w + I_{ext} \\ \frac{dw}{dt} &= \frac{v + a - b w}{\tau} \end{align*}

where vv is the membrane potential, ww is the recovery variable, aa and bb are model parameters, τ\tau is the time scale, and IextI_{ext} is the external current. The function uses SciPy’s ODE solver (scipy.integrate.solve_ivp ) to integrate the system from t_start to t_end. Only the basic two-variable model is exposed; external stimulus or spatial extensions are not supported. 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:

=FITZHUGH_NAGUMO(v_initial, w_initial, a, b, tau, i_ext, t_start, t_end, [timesteps], [solve_ivp_method])
  • v_initial (float, required): Initial membrane potential.
  • w_initial (float, required): Initial recovery variable.
  • a (float, required): Parameter a.
  • b (float, required): Parameter b.
  • tau (float, required): Time scale parameter.
  • 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, W, representing time, membrane potential, and recovery variable at each step. If the input is invalid or integration fails, a string error message is returned.

Examples

Example 1: Basic Case

Inputs:

v_initialw_initialabtaui_extt_startt_endtimestepsmethod
0.00.00.70.812.50.50.01.010RK45

Excel formula:

=FITZHUGH_NAGUMO(0.0, 0.0, 0.7, 0.8, 12.5, 0.5, 0.0, 1.0, 10)

Expected output:

tVW
0.0000.0000.000
0.1110.0580.006
0.2220.1230.013
0.3330.1940.021
0.4440.2720.029
0.5560.3580.038
0.6670.4510.047
0.7780.5520.058
0.8890.6590.069
1.0000.7720.081

Example 2: With Optional Timesteps and Method (RK23)

Inputs:

v_initialw_initialabtaui_extt_startt_endtimestepsmethod
0.00.00.70.812.50.50.01.010RK23

Excel formula:

=FITZHUGH_NAGUMO(0.0, 0.0, 0.7, 0.8, 12.5, 0.5, 0.0, 1.0, 10, "RK23")

Expected output:

tVW
0.0000.0000.000
0.1110.0580.006
0.2220.1230.013
0.3330.1940.021
0.4440.2720.029
0.5560.3580.038
0.6670.4510.047
0.7780.5510.058
0.8890.6590.069
1.0000.7720.081

Example 3: All Args Specified

Inputs:

v_initialw_initialabtaui_extt_startt_endtimestepsmethod
1.00.50.70.812.50.50.02.010RK45

Excel formula:

=FITZHUGH_NAGUMO(1.0, 0.5, 0.7, 0.8, 12.5, 0.5, 0.0, 2.0, 10, "RK45")

Expected output:

tVW
0.0001.0000.500
0.2221.1440.524
0.4441.2720.551
0.6671.3790.579
0.8891.4620.608
1.1111.5200.638
1.3331.5580.669
1.5561.5790.699
1.7781.5890.730
2.0001.5900.760

Example 4: Different Parameters

Inputs:

v_initialw_initialabtaui_extt_startt_endtimestepsmethod
-1.00.20.50.710.00.30.01.510RK45

Excel formula:

=FITZHUGH_NAGUMO(-1.0, 0.2, 0.5, 0.7, 10.0, 0.3, 0.0, 1.5, 10)

Expected output:

tVW
0.000-1.0000.200
0.167-1.0930.189
0.333-1.1810.176
0.500-1.2610.162
0.667-1.3320.147
0.833-1.3910.131
1.000-1.4400.114
1.167-1.4790.097
1.333-1.5070.079
1.500-1.5270.061

Python Code

from scipy import integrate as scipy_integrate import numpy as np def fitzhugh_nagumo(v_initial, w_initial, a, b, tau, i_ext, t_start, t_end, timesteps=10, solve_ivp_method='RK45'): """ Wrapper around scipy.integrate.solve_ivp that numerically solves the FitzHugh-Nagumo system of ordinary differential equations for neuron action potentials. This function wraps the scipy.integrate.solve_ivp solver. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html Args: v_initial: Initial membrane potential. w_initial: Initial recovery variable. a: Parameter a. b: Parameter b. tau: Time scale parameter. 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, W. 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 input types try: v0 = float(v_initial) w0 = float(w_initial) a = float(a) b = float(b) tau = float(tau) 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 tau <= 0: return "Invalid input: tau must be positive." 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'." # Create time array for evaluation t_eval = np.linspace(t0, t1, ntp) # FitzHugh-Nagumo ODE system def fhn_ode(t, y): v, w = y dv_dt = v - v**3 / 3 - w + i_ext dw_dt = (v + a - b * w) / tau return [dv_dt, dw_dt] # Integrate try: sol = scipy_integrate.solve_ivp( fhn_ode, [t0, t1], [v0, w0], method=solve_ivp_method, dense_output=False, t_eval=t_eval ) except Exception as e: return f"Integration error: {e}" if not sol.success: return f"Integration failed: {sol.message}" # Format output: header row then data rows result = [["t", "V", "W"]] for i in range(len(sol.t)): t_val = float(sol.t[i]) v_val = float(sol.y[0][i]) w_val = float(sol.y[1][i]) # Disallow nan/inf if any([ not isinstance(t_val, float) or not isinstance(v_val, float) or not isinstance(w_val, float), t_val != t_val or v_val != v_val or w_val != w_val, # NaN check abs(t_val) == float('inf') or abs(v_val) == float('inf') or abs(w_val) == float('inf') ]): return "Invalid output: nan or inf detected." result.append([t_val, v_val, w_val]) return result

Example Workbook

Link to Workbook 

Last updated on