%the right hand side for ode simulation:
function s_prime=deRHS_coupled(t,s)
global gnabar gkbar gl Vna Vk Vl  gnabar gkbar gl Vna Vk Vl Inp rn0 coup A 

V = s(1:2);
W = s(3:4);


%Input = Inp/cosh(mod(t,BCL)-BCL/4);
Input = Inp;
n = W;
     
AM=.1*(25.-V)./(exp(2.5 -0.1*V)-1.);
BM=4.*exp(-V/18.);
AN=.01*(10.-V)./(exp(1.-0.1*V)-1.);
BN=.125*exp(-V/80.);

h = rn0 - n;
aminf = AM./(AM+BM);
aminf = aminf.^3;

Ina = gnabar.*aminf.*h.*(V-Vna) ;

Ik = gkbar.*n.^4.*(V-Vk);
Icl = gl.*(V-Vl);
      
Fv = -Ina-Ik-Icl + coup*A*V;
Fw=AN.*(1.-n)-BN.*n;

s_prime = [Fv+Input ;Fw];
