
function chay_over(ui)
%code by Timothy Jones based on paper by Dr. Medvedev
global u
u = ui;


tspan=[0 350];
figure(1)
axis([-6 0 0 0.6])
hold on

for i=-15.99:0.2:25
    
x0=[i; 0];
%[t,x]=ode23(@Chay_works, tspan, x0);
[t,x] = ode45(@Chay_works, tspan, x0);

v=x(:,1);
n=x(:,2);
plot(v,n, '-black')
drawnow
end


% for i=0.36:0.02:0.6
%     
% x0=[0; i];
% [t,x]=ode23('Chay_work', tspan, x0);
% v=x(:,1);
% n=x(:,2);
% plot(v,n, '-b')
% drawnow
% end

EI=10;
eps=0.1353;
gam=0.01833;
EK=-7.5;
a=1.059;
delt=0.02;
ECa=10;
l=0.00412;
kv=10;
El=-4;
rho=.01174;
kt=1/230;
%u=0.118;
beta=delt*u/(1+u);

v=-6:0.005:0;

alpham=(2.5+v)./(1-exp(-(v+2.5)));
betam=4*exp(-(v+5)/1.8);
alphah=0.07*exp(-(v+5)/2);
betah=1./(1+exp(-(v+2)));
alphan=0.1*(2+v)./(1-exp(-(v+2)));
betan=0.125*exp(-(v+3)/8);
tau=1./(alphan+betan);
minf=alpham./(alpham+betam);
ninf=alphan./(alphan+betan);
hinf=alphah./(alphah+betah);

plot(v,ninf, '-r', 'linewidth', 2)
plot(v, sqrt(sqrt((a*minf.^3.*hinf.*(EI-v)+l.*(El-v))./(v-EK) - beta)), '-b', 'linewidth', 2)

srt=int2str(3);


%plot(t,n,'--r')
xlabel('v')
ylabel('n')
print -dpng 'str'


function xdot=Chay_works(t,x)
global u

v=x(1);
n=x(2);

%u=paramu;
EI=10;
eps=0.1353;
gam=0.01833;
EK=-7.5;
a=1.059;
delt=0.02;
ECa=10;
l=0.00412;
kv=10;
El=-4;
rho=.01174;
kt=1/230;
%u=0.118;
%u=paramu;
beta=delt*u/(1+u);

alpham=(2.5+v)/(1-exp(-(v+2.5)));
betam=4*exp(-(v+5)/1.8);
alphah=0.07*exp(-(v+5)/2);
betah=1/(1+exp(-(v+2)));
alphan=0.1*(2+v)/(1-exp(-(v+2)));
betan=0.125*exp(-(v+3)/8);
tau=1/(alphan+betan);
minf=alpham/(alpham+betam);
ninf=alphan/(alphan+betan);
hinf=alphah/(alphah+betah);

dv=(a*((minf)^3)*hinf*(EI-v)+(n^4)*(EK-v)+ beta*(EK-v)+l*(El-v))/eps;
dn=(ninf-n)/tau;
xdot=[dv dn]';

