function eeuler(n)
% Solves the ivp y'=y - 1/(1+x)^2 - 1/(1+x), y(0)=2 
% by the backward Euler method
%
fprintf('\n')
%
for iit=1:10
%
nn=2^(iit-1)*n;
uu(iit)=1/nn;
%
h=1/nn;
%
y=2;
%
for i=0:nn
t=i*h;
t1=(i+1)*h;
ex=exp(t)+(1/(1+t));
er(i+1)=abs(ex-y);
m= - 1/(1+t1)^2 - 1/(1+t1);
y=(y+h*m)/(1-h);
end
u1(iit)=max(er);
fprintf('h =%12.6f        maxerr = %15.6e\n',h,u1(iit))
end
u1';
loglog(uu,u1,'b+')
xlabel('h');ylabel('Error');

