
%testing lte of Euler schemes and midpoint


function e=testlte17(sol,f,t,h0,M=5)
%computes lte of explicit/implicit Euler and midpoint
% at t for  h=h0/h0/2,..,h0/(2^(M))
%sol=@exp;f=@(x,t) x;t=1;h0=0.1;e=testlte17(sol,f,t,h0)
 
 e=zeros(M+1,2);
 h=h0;
 x=sol;
 for k=0:M,
  e(k+1,1)=norm(x(t+h)-x(t)-h*f(x(t),t),'inf');
  e(k+1,2)=norm(x(t+h)-x(t)-h*f(x(t+h),t+h),'inf');
  e(k+1,3)=norm(x(t+2*h)-x(t)-2*h*f(x(t+h),t+h),'inf');
  h*=0.5;
 end
 disp("in columns tests of order of LTE for explicit,Euler, implicit Euler and midpoint");
 e(1:M,:)./e(2:M+1,:)
end
    
