function   [T,W]=euler51(Fun,t0,tlast,w0,N)
%    function   [T,W]=euler51(Fun,t0,tlast,w0,N)
%%%%%%%%%%% Eulers Algorithm for Initial Value Problems %%%%%%%%%%%
%% 
%% Solve y'= f(t,y),   t0<= t <=tlast,  y(t0)=  w0
%%
%% It is assumed that you have the function f(t,y) defined elsewhere 
%% as a function in a .m file
% INPUT:
% Fun   - String containing name of function m-file (enclose in '  ')
% t0    - Initial value of t.
% tlast - Last value of t.
% w0    - Initial value.
% N     - The number of steps
%
% OUTPUT:
% T  - time points (column-vector).
% W  - Solution column-vector for corresponding T-values.
%
% The result can be displayed by: plot(T,W)

h=(tlast-t0)/N;t=t0;w=w0;
T=t;W=w;

%% Step 2
for i=1:N;
 w = w + h*feval(Fun, t, w); %%Step 3
 t = t0 + i*h;                      %%Step 3
 T=[T;t]; W = [W;w];               %%Step 4
end; 
