function euler02_demo
%
% Initialization step
N = 10;
h_vect = zeros(1,N); 
err_vect = h_vect; 
h = 0.2; 

t=0:0.05:3;
x = -1 - t + 2 * exp(t);           % The exact solution

%tic;
for i = 1:N
  h_vect(i) = h;                        % The new step size vector
  [s, y]  = eul (@ypt, 0, 3, 1, h);     % The approximate solution
  plot(t, x, s, y, 'o', 'LineWidth',2)  % Plot both
  grid
  
  %  pause
  z = -1 - s + 2 * exp(s);              % The exact solution at the s points
  maxerror = max(abs(z - y));           % The biggest error
  err_vect(i) = maxerror;               % The new error vector
%  h_vect;                               % Display the vector of step sizes
%  err_vect;                             % Display the vector of errors
  h = h / 2;                            % The step size for the next time
end
%toc

% See error
loglog(h_vect, err_vect, '-', 'LineWidth', 2);
hold on
loglog(h_vect, err_vect, 'x', 'LineWidth', 4);
xlabel('Step size'); 
ylabel('Maximum error'); 
grid
hold off

end % function

function ypt = ypt(t, y)
%
  ypt = y + t;
end
