t = linspace(0,tMax,num);
num1 = find(t > tStart, 1 );
[An, Bn, Am, Bm, Ah, Bh] = AlphaBeta(V(1), T);
gNa(1) = gNamax * m(1)^3 * h(1);
JK(1) = gK(1) * (V(1) - VK);
JNa(1) = gNa(1) * (V(1) - VNa);
Vadj = (Jext(1) - JK(1) - JNa(1))/gL(1);
JL(1) = gL(1) * (V(1) - VR + Vadj);
Jm(1) = JNa(1) + JK(1) + JL(1);
V(1) = VR + (dt/Cm) * (-JK(1) - JNa(1) - JL(1) + Jext(1));
[An, Bn, Am, Bm, Ah, Bh] = AlphaBeta(V(cc), T);
An = sf * An; Am = sf * Am; Ah = sf * Ah;
Bn = sf * Bn; Bm = sf * Bm; Bh = sf * Bh;
n(cc+1) = n(cc) + dt * (An *(1-n(cc)) - Bn * n(cc));
m(cc+1) = m(cc) + dt * (Am *(1-m(cc)) - Bm * m(cc));
h(cc+1) = h(cc) + dt * (Ah *(1-h(cc)) - Bh * h(cc));
gK(cc+1) = n(cc+1)^4 * gKmax;
gNa(cc+1) = m(cc+1)^3 * h(cc+1) * gNamax;
JK(cc+1) = gK(cc+1) * (V(cc) - VK);
JNa(cc+1) = gNa(cc+1) * (V(cc) - VNa);
JL(cc+1) = gL(cc+1) * (V(cc) - VR + Vadj);
Jm(cc+1) = JNa(cc+1) + JK(cc+1) + JL(cc+1);
V(cc+1) = V(cc) + (dt/Cm) * (-JK(cc+1) - JNa(cc+1) - JL(cc+1) + Jext(cc+1));
set(gcf,'units','normalized');
set(gcf,'position',[x2 y1 w d]);
plot(x,y,'b','linewidth',LW);
xlabel('time t [ ms ]'); ylabel('membrane voltage V_m [ mV ]');
function [An, Bn, Am, Bm, Ah, Bh] = AlphaBeta(V, T)
An = phi * (eps + 0.10 - 0.01 .* dV) ./ (eps + exp(1 - 0.1 .* dV) - 1);
Am = phi * (eps + 2.5 - 0.1 .* dV) ./ (eps + exp(2.5 - 0.1 .* dV) - 1);
Ah = phi * 0.07 .* exp(-dV ./ 20);
Bn = phi * 0.125 .* exp(-dV ./ 80);
Bm = phi * 4 .* exp(-dV/18);
Bh = phi * 1 ./ (exp(3.0 - 0.1 .* dV) + 1);