function [t,u]=exp_euler(u0,T,N,fhandle)
% C.E. Powell, MATH64082
% Explicit Euler code for IVP (3.5) 
% inputs: 
%        u0  - initial condition (column vector, length d);
%        T   - final time
%        N   - no. of intervals
%        fhandle - function handle to define vector-valued function f
% outputs:
%        t   - vector of grid values t_n, n=0,1, ...., N.
%        u   - d x (N+1) matrix, where ith column contains Explicit Euler
%              approximation at time step t_i-1, i=1,...,N+1.

Dt=T/N;            % set time step
u=zeros(2,N+1);    % preallocate numerical solution u
t=[0:Dt:T]';       % make vector of t_n values on [0,T]
u(:,1)=u0; u_n=u0; % set inital data
for n=1:N          % loop over time steps
  u_new=u_n+Dt*fhandle(u_n); % explicit Euler step
  u(:,n+1)=u_new; u_n=u_new;
end

