% Unit 5 (MATLAB Course @ UAM)
% (c) Alexander Knebe

%==================================================
% Euler method for ordinary differential equations
%==================================================
function [f,x] = euler(g, x0, f0, xN, N)

% initialisation block
%----------------------
% step size
dx   = (xN-x0)/(N-1);

% arrays
x    = linspace(x0,xN,N);
f    = zeros(1,N);
%x(1) = x0; this is automatically initialized by linspace()
f(1) = f0;


% integration block
%-------------------
for i=1:N-1
    f(i+1) = f(i) + g(f(i),x(i)).*dx;
end
