clear all
clc

%try # of steps that are from 10 to 10^powe
powe=6;
expslope=-4;
for jN=1:powe
N=10^jN;

%initial position
xo=.5;
%timeline
T=linspace(0,1,N);
dt=T(2)-T(1);
%analytic solution
xan=xo./((1-xo).*exp(-T)+xo);
a1=1/6;
a2=1/3;
a3=1/3;
a4=1/6;
b1=1/2;
b2=1/2;
b3=1;

x(1)=xo;
for it=2:N
    %t=T(it-1);
    k1=logi(x(it-1));
    k2=logi(x(it-1)+b1*k1*dt);
    k3=logi(x(it-1)+b2*k2*dt);
    k4=logi(x(it-1)+b3*k3*dt);
x(it)=x(it-1)+(a1*k1+a2*k2+a3*k3+a4*k4)*dt;
%x(it)=x(it-1)+(k1)*dt;
end
Delta(jN)=abs(x(end)-xan(end));
end

figure(1)
semilogy([1:powe],Delta,'k','LineWidth',2)
hold on
semilogy([1:powe],Delta(1)*10.^(expslope*[0:powe-1]),'-r','LineWidth',3)