function [t,y] = myeuler1(f,tinit,tend,yinit,n)
%
% Scalar case
% Euler approximation for initial value problem,
% dy/dt = f(t,y), y(tinit) = yinit.
% Approximations y(1),...,y(n+1) are calculated at
% the n+1$ pointa t(1),...,x(n+1) in the interval
% [tinit, tend]. The right-hand side of the differential
% equation is defined as an inline function f.

% Calculation of h from tinit, tend, and n.
h = (tend-tinit/n);

% Initialize t and y as length n+1 column vectors.
t = zeros(n+1,1);
y = zeros(n+1,1);

% Calculation of point t(i) and the corresponding
% approximate values y(i) from the Euler Method formula

t(1) = tinit;
y(1) = yinit;
for i=1:n
    t(i+1) = t(i)+h
    y(i+1) = y(i)+h*f(t(i),y(i));
end
