%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Implements Euler's method for finding an approximate solution of
%% the initial value problem
%%
%%      y' = f(x,y)
%%   
%%   y(x0) = y0
%%
%% Usage: [x,y] = Euler(f,x0,y0,x1,N)
%%
%% In:
%%
%%  f:   the right-hand-side function
%%  x0:  initial x-value
%%  y0:  initial y-value
%%  x1:  final x-value
%%   N:  number of steps to take
%%
%%
%% Out:
%%  x: vector of x-coordinates
%%  y: vector of y-coordinates of the (approximate) solution 
%%
function [x,y] = Euler(f,x0,y0,x1,N)
  h = (x1-x0)/N;
  x = zeros(1,N+1);
  y = zeros(1,N+1);
  X = x0;
  Y = y0;

  x(1) = X;
  y(1) = Y;
  for( k=2:N+1)
    Y = Y + f(X,Y)*h
    X = X + h;
    x(k) = X;
    y(k) = Y;
  end
end
