% function y = ab5(a,b,n,y0,f)
%
% Math 5620
%
% Solves the IVP
%   y' = f(t,y), t in [a,b]
%   y(a) = y0
% using the Adams-Bashforth Five-Step Explicit Method
% 
% Inputs
%  a,b   endpoints of time interval
%  n     number of time steps (h = (b-a)/n)
%  y0    initial condition, y(a)
%  f     function handle to the function f(t,y).
%        For example:
%         f = @(t,y)  t/2 + y*t;
%
% Outputs
%  y     vector of length n+1 such that y(i) \approx y( a + (i-1)*h), i=1..n+1
%
% THIS IS A STUB TO BE IMPLEMENTED

function y = ab5(a,b,n,y0,f)
h=(b-a)/n;

% NOTE: to avoid unnecessary calculations we store all function evaluations
%       in the vector fs(i). 
%           fs(i) contains f(a+(i-1)*h,y(a+(i-1)*h))
%       it's possible to avoid this memory overhead by using some FIFO structure

% prime the first steps with RK4
y=rk4(a,a+4*h,4,y0,f); % calls your own rk4.m
for i=1:5,
 ti=a+(i-1)*h;
 fs(i) = f(ti,y(i));
end;

% carry out method
for i=5:n,
 y(i+1)  = y(i) +  % TO BE COMPLETED
end;
