
%testujemy Adams-bashford 2 krokowy
%tests of Adams-bashford 2 step

n=100;t0=0;T=1;
h=(T-t0)/n;
pw=@(x,t) -x;
sol=@(t) exp(-t);
[x,t]=adamsb2s17(pw,x0=1,x1=sol(h),t0,T,n);
plot(t,x,";Adams-B2step;",t,s=sol(t),";exp(-t);");
pause(2);
plot(x-s,";error;");


%seems to work...

n=10;
er=1;
M=5;
x0=1;
err=zeros(M,3);
for k=1:M,
  h=(T-t0)/n;
  f0=pw(x0,t0);
  %x(1) exact i.e. x(t(1))
  [x,t]=adamsb2s17(pw,x0,x1=sol(t0+h),t0,T,n);
  %x(1) computed by modified Euler scheme - convergence of order 2 
  [xe,t]=adamsb2s17(pw,x0,x1=x0+h*f0,t0,T,n);
  %x(1) computed by forward Euler scheme - convergence of order 1 
   x1=x0+0.5*h*(f0+pw(x0+h*f0,t0+h));
  [xh,t]=adamsb2s17(pw,x0,x1,t0,T,n);
  s=sol(t);
  err(k,1)=norm(s-x,'inf');
  err(k,2)=norm(s-xe,'inf');
  err(k,3)=norm(s-xh,'inf');
  n*=2;
end

err(1:M-1,:)./err(2:M,:)
%so close to four 2^2 for all x(1)