gistlib
main.m% Constants Cm = 1; % Membrane capacitance gNa = 120; % Sodium conductance ENa = 115; % Sodium equilibrium potential gK = 36; % Potassium conductance EK = -12; % Potassium equilibrium potential gL = 0.3; % Leak conductance EL = 10.6; % Leak equilibrium potential dt = 0.01; % Time step size t_max = 50; % Maximum simulation time % Initial values V = 0; % Membrane voltage m = 0; % Sodium activation variable h = 0; % Sodium inactivation variable n = 0; % Potassium activation variable % Arrays to store values V_array = zeros(1, t_max/dt); m_array = zeros(1, t_max/dt); h_array = zeros(1, t_max/dt); n_array = zeros(1, t_max/dt); % Simulation loop for i = 1:(t_max/dt) % Calculate membrane currents INa = gNa * m^3 * h * (V - ENa); IK = gK * n^4 * (V - EK); IL = gL * (V - EL); % Update gating variables using HH model equations alpha_m = (0.1 * (V + 40)) / (1 - exp(-(V + 40)/10)); beta_m = 4 * exp(-(V + 65)/18); alpha_h = 0.07 * exp(-(V + 65)/20); beta_h = 1 / (1 + exp(-(V + 35)/10)); alpha_n = (0.01 * (V + 55)) / (1 - exp(-(V + 55)/10)); beta_n = 0.125 * exp(-(V + 65)/80); m = m + dt * ((alpha_m * (1 - m)) - (beta_m * m)); h = h + dt * ((alpha_h * (1 - h)) - (beta_h * h)); n = n + dt * ((alpha_n * (1 - n)) - (beta_n * n)); % Update membrane voltage using forward Euler method dv = (1 / Cm) * (-(INa + IK + IL)); V = V + dt * dv; % Store values in arrays V_array(i) = V; m_array(i) = m; h_array(i) = h; n_array(i) = n; end % Plot the membrane voltage time = 0:dt:t_max-dt; plot(time, V_array); xlabel('Time (ms)'); ylabel('Membrane Voltage (mV)'); title('Hodgkin-Huxley Model using Forward Euler'); 1720 chars60 lines
% Constants Cm = 1; % Membrane capacitance gNa = 120; % Sodium conductance ENa = 115; % Sodium equilibrium potential gK = 36; % Potassium conductance EK = -12; % Potassium equilibrium potential gL = 0.3; % Leak conductance EL = 10.6; % Leak equilibrium potential dt = 0.01; % Time step size t_max = 50; % Maximum simulation time % Initial values V = 0; % Membrane voltage m = 0; % Sodium activation variable h = 0; % Sodium inactivation variable n = 0; % Potassium activation variable % Arrays to store values V_array = zeros(1, t_max/dt); m_array = zeros(1, t_max/dt); h_array = zeros(1, t_max/dt); n_array = zeros(1, t_max/dt); % Simulation loop for i = 1:(t_max/dt) % Calculate membrane currents INa = gNa * m^3 * h * (V - ENa); IK = gK * n^4 * (V - EK); IL = gL * (V - EL); % Update gating variables using HH model equations alpha_m = (0.1 * (V + 40)) / (1 - exp(-(V + 40)/10)); beta_m = 4 * exp(-(V + 65)/18); alpha_h = 0.07 * exp(-(V + 65)/20); beta_h = 1 / (1 + exp(-(V + 35)/10)); alpha_n = (0.01 * (V + 55)) / (1 - exp(-(V + 55)/10)); beta_n = 0.125 * exp(-(V + 65)/80); m = m + dt * ((alpha_m * (1 - m)) - (beta_m * m)); h = h + dt * ((alpha_h * (1 - h)) - (beta_h * h)); n = n + dt * ((alpha_n * (1 - n)) - (beta_n * n)); % Update membrane voltage using forward Euler method dv = (1 / Cm) * (-(INa + IK + IL)); V = V + dt * dv; % Store values in arrays V_array(i) = V; m_array(i) = m; h_array(i) = h; n_array(i) = n; end % Plot the membrane voltage time = 0:dt:t_max-dt; plot(time, V_array); xlabel('Time (ms)'); ylabel('Membrane Voltage (mV)'); title('Hodgkin-Huxley Model using Forward Euler');
gistlibby LogSnag