% EPSC

% APMA 0410
% Fall 2012

I_max = 390*1e-12;
tau = 0.2*1e-3;
tau_m = 15*1e-3;
R_m = 60*1e6;
E_rest = -60*1e-3;

A = tau/tau_m;
B = E_rest*tau/tau_m;
C = exp(1)*R_m*I_max*tau/tau_m;



ds = .01;  % time step for Euler algorithm
s_min = 0;
s_max = 300;

N = ceil((s_max-s_min)/ds); % number of steps

s = zeros(1,N);
x = E_rest*ones(1,N);
s_current = 0;

for n = 1:N
    s_current = s_current + ds;
    deriv = -A*x_current + B + C*s_current*exp(-s_current);
    x_current = x_current + ds*deriv;
    s(n) = s_current;
    x(n) = x_current;
end

t = tau*s;

plot(t,1e3*x,'linewidth',2)
xlabel('t (sec)')
ylabel('V (mV)')
grid on
