% Function applying the simple Euler method to a given equation
%                   y' = fun(x,y) 
%
% The user must specify:
%  -  the function  fun; 
%  -  the integration span  xspan (a 2-component vector);
%  -  the integration step size  h;  and
%  -  the initial value,  y_init,  for y.

function [X,Y] = hw1_EX_Euler_callsfun(fun, xspan, h, y_init);

Y(1) = y_init;
X = xspan(1) :h: xspan(2);

for n = 1 : length(X)-1
    Y(n+1) = Y(n) + h*feval(fun, X(n), Y(n));
             % command feval (which stands for f-unction eval-uation)
             %  computes fun(X(n),Y(n))  ("fun" is defined in line 2 above),
             %  where the actual name for  fun  is provided in the main code.
             %  In this case, the name for  fun  is the "string" after "@" in line 27
             %  (i.e.,  fun4_hw1_EX_main4Euler )  in  hw1_EX_main4Euler.m).
end