function [x,y]=myeuler(f,xinit,yinit,b,n)

% Euler approximation for initial value problem,
% dy/dx=f(x,y), y(xinit)=yinit.
% Approximation y(1),...,y(n+1) are calculated at the
% n+1 points x(1),...,x(n+1) in the interval
% [xinit,b]. The right hand side of the differential equation
% equation is defined as an inline function f.

% calculation of h from xinit, b, and n.

h=(b-xinit)/n;

% initialize x and y as length n+1 column vectors.

x=zeros(n+1,1);
y=zeros(n+1,1);

% calculation of points x(i) and the corresponding 
% approximate values y(i) from the Euler Method formula.

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