%euler method simulator

deltat=0.2 ; %timestep
Tmax=10;

tlist=linspace(0,Tmax,Tmax/deltat +1) ;
Vlist=zeros(1,length(tlist));

%initialize
V0=0;
Vlist(1)=V0;

%define input currents
%Iapplist=ones(1,length(tlist));
Iapplist=sin(tlist);
%Iapplist=ones(1,length(tlist))+sin(tlist);



%circuit parameters
R=2;
C=1;


for n=1:length(tlist)-1
    t=tlist(n);
    Vlist(n+1)=Vlist(n) + (-Vlist(n)/(R*C) + Iapplist(n)/C )*deltat;
end

set(0,'defaultaxesfontsize',20);
set(0,'defaulttextfontsize',20); 

figure
set(gca,'FontSize',16)
subplot(211)
plot(tlist,Vlist,'.-','LineWidth',2,'MarkerSize',26); hold on
xlabel('t','Fontsize',20); ylabel('V(t)','Fontsize',20); 
legend('Euler Approx')

subplot(212)
plot(tlist,Iapplist,'-','LineWidth',2); hold on
xlabel('t','Fontsize',20); ylabel('Iapp(t)','Fontsize',20); 