% Forward Euler scheme for the LIF model

Vthres=-50;
Vreset=-70;
C=1;
gL=0.05;
EL=-65;
I=2;

dt=0.01; % timestep
tstop=50;

N=ceil(tstop/dt);
V=zeros(1,N); % voltage vector
V(1)=Vreset;
t=0.0;

tspike=[]; %spiketime array

for i=2:N; % timeloop
    
t=t+dt;
    V(i)=V(i-1)+dt/C*(-gL*(V(i-1)-EL)+I);
    
     
if (V(i)>Vthres) % check if spike happened
             
V(i)=Vreset;
             tspike=[tspike t];
             
         end   
     
   
end

time=[dt:dt:tstop];

plot(time,V);



