function [x,y] = euler(f,x0,xf,y0,N)
% solves ODE dy/dx = f(x,y) at x0 <= x <= xf with initial condition y(x0) = y0
% the method uses N steps of the Euler's method 

% in the example under discussion the function f(x,y) = y, x0 = 0, xf = 1, y0 = 1
% and the output values [x,y] give the vectors for points of x and y(x)
% the value y(xf) approximates the number e

dx = (xf-x0)/N; % the step size of the Euler's method

x = x0 : dx : xf; % the row vector for (N+1) points of x between x=x0 and x=xf

ff = inline(f); % the function f given as an input string is tranformed into an inline function ff

% The Euler method replaces the derivative dy/dx by the finite difference (y_(k+1)-y_k)/dx
% The iterations (y_k -> y_(k+1)) are then given as 
%         y_(k+1) = y_k + dx*f(x_k,y_k)
% in the example under discussion, this method gives 
%         y_(k+1) = y_k*(1+dx)

y(1) = y0;
for k = 1 : N % this is the MATLAB "for" loop (a sequence of operations when k runs from 1 to N)
    xx = x(k); % assigning the current value for x_k
    yy = y(k); % assigning the current value for y_k
    y(k+1) = yy + dx*ff(xx,yy); % the Euler's method 
    % Notice here that the length of vector y is increased by one automatically 
    %           (no needs to declare y as vector of a certain length)
end % the end of the "for" loop


