dt = 0.08;
Vm = 0;
t(1)=0;
i_inj = 17;
x = [0.317676914060697 0.596120753508460 0.0529324852572496 0];
y = [0.317676914060697 0.596120753508460 0.0529324852572496 0];
i = 1;
k = 1;
while t(k)<11
x(i+1,:) = x(i,:)+dt.*derivs(t(k),x(i,:),i_inj);
k1 = dt.*derivs(t(k),y(i,:),i_inj);
k2 = dt.*derivs(t(k)+0.5*dt,y(i,:)+0.5.*k1,i_inj);
y(i+1,:) = k2+y(i,:);
dif = abs(x(i+1,4)-y(i+1,4));
if (dif>=0.1)
dt = dt*0.5;
else
t(k+1) = dt+t(k);
i = i+1;
k = k+1;
end
end
function y = derivs(t,x,I_inj)
g_Kbar = 36;
E_K = -12;
g_Nabar = 120;
E_Na = 115;
Gm = 0.3;
V_rest = 10.613;
V=x(4);
if(V == 10)
alpha_n = 1/10;
else
alpha_n = (10-V)./(100*(exp(1-V/10)-1));
end
beta_n = 0.125*exp(-V/80);
n=x(1);
dndt = alpha_n*(1-n)-beta_n*n;
y(1) = dndt;
alpha_h = 0.07*exp(-V/20);
beta_h = 1/(exp(3-V/10)+1);
h=x(2);
dhdt = alpha_h*(1-h)-beta_h*h;
y(2) = dhdt;
if (V==25)
alpha_m = 1;
else
alpha_m = (25-V)/(10*(exp(2.5-V/10)-1));
end
beta_m = 4*exp(-V/18);
m=x(3);
dmdt = alpha_m*(1-m)-beta_m*m;
y(3) = dmdt;
if t>=1 && t<=1.5
dVdt = I_inj+g_Nabar.*m.^3.*h.*(E_Na-V)+g_Kbar.*n.^4.*(E_K-V)+Gm*(V_rest-V);
else
dVdt = g_Nabar.*m.^3.*h.*(E_Na-V)+g_Kbar.*n.^4.*(E_K-V)+Gm*(V_rest-V);
end
y(4) = dVdt;
end