function [ yFinal ] = eulerFinal( xstart, ystart, xend, h )
%eulerFinal: use the Euler method to solve y'=x.y^2 but only compute yEnd
%   (instead of computing the full list of y values)
    
% the "round" function gives the closest integer to some real number 
    n = round((xend-xstart+eps)/h);
    % adjust h so that the range is exactly n*h
    % (to ensure that we have exactly x(n+1) = xend, remember x(1)=xstart)
    hTrue = (xend-xstart)/n;

    xx = xstart;
    yy = ystart;
    
    for i=1:n
        xx = xstart + hTrue*(i-1);  % this is x(i)
        yprime = xx*yy^2;           % at this point yy = Y(i)
        yy = yy + hTrue*yprime;     % this is Y(i+1)
    end
    
    yFinal = yy;  % this is the answer, our estimate of y(xend)
    
end

