%
%   EULER1.M   Use Euler Method for Numerical Solution of IVPs
%
%   This function solves a single first-order ODE via Euler's Method
%
%   The inputs to the function are:
%      fxy = string variable with the name of the function file containing f(x,y)
%      xo,xf = initial and final values of the independent variable (scalars)
%      yo = initial value of dependent variable at xo 
%      N = number of intervals to use between xo and xf
%   The outputs to the function are:
%      X = vector containing values of the independent variable
%      Y = the estimated dependent variable at each value of the independent variable
%

      function [X,Y] = euler1(fxy,xo,xf,yo,N)
%
%   compute step size and size of output variables
      if N < 2   N = 2;   end  % set minimum number for N
      h = (xf-xo)/N;           % step size
      X = zeros(N+1,1);        % initialize independent variable
      Y = zeros(N+1,1);        % initialize dependent variables
%
%   set initial conditions
      X(1) = xo;   Y(1) = yo;
%
%   begin computational loop
      for i = 1:N
        k1 = h*feval(fxy,X(i),Y(i));   % evaluate function
        Y(i+1) = Y(i) + k1;            % increment dependent variable
        X(i+1) = X(i) + h;             % increment independent variable
      end
%
%   end of function
%

