function [t y] = eulerode(fprime, tspan, y0, dt)
% EULERODE  Solve ODE using Euler's method
%  [t y] = EULERODE(fprime, dt, y0) solves the ordinary differential 
%  equation  y' = fprime(t, y).  
%  INPUT:
%   fprime(t,y) should be a function handle which represents the derivative
%   tpan should be a vector with 2 entries for the left and right endpoints
%    of the interval you are solving the ODE on
%   y0 is an initial condition, i.e., y(t(1))
%   dt is a step size.  If not specified, dt is set to be 1e-4.

% Set default dt
if (nargin < 4)
    dt = 1e-4;
end

t = tspan(1):dt:tspan(2);
y = zeros(size(t));  y(1) = y0;

% main loop
for j = 2:length(t)
    y(j) = y(j-1) + dt*fprime(t(j-1), y(j-1));
end

plot(t,y)
