function [tnew,ynew,fnew] = ABStep(f,tc,yc,fvals,h,d)
%
% Single step of the d-th order Adams-Bashforth method.
%
% f is a handle that references a function of the form f(t,y)
% where t is a scalar and y is a column m-vector.
%
% yc is an approximate solution to y'(t) = f(t,y(t)) at t=tc.
%
% fvals is an m-by-d matrix where fvals(:,i) is an approximation
% to f(t,y) at t = tc +(1-i)h, i=1:d
%
% h is the time step.
%
% d is the order of the AB method used, 1<=d<=5.
%
% tnew=tc+h.
% ynew is an approximate solution at t=tnew.
% fnew = f(tnew,ynew).

if d==1
ynew = yc + h*fvals;
elseif d==2
ynew = yc + (h/2)*(fvals*[3;-1]);
elseif d==3
ynew = yc + (h/12)*(fvals*[23;-16;5]);
elseif d==4
ynew = yc + (h/24)*(fvals*[55;-59;37;-9]);
elseif d==5
ynew = yc + (h/720)*(fvals*[1901;-2774;2616;-1274;251]);
end
tnew = tc+h;
fnew = f(tnew,ynew);