%euler method simulator

deltat=0.1 ; %timestep
Tmax=10;

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

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


%circuit parameters
R=1;
C=1;

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



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

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

