function [tvals,yvals,fvals] = ABStart(f,t0,y0,h,d)
% Generates enough starting values for the dth order Adams-Bashforth method.
% Uses k-th order Runge-Kutta to generate approximate solutions to
%
% y'(t) = f(t,y(t)) y(t0) = y0
%
% at t = t0, t0+h, ... , t0 + (d-1)h.
%

% f is a handle that references a function of the form f(t,y).
% t0 is the initial time.
% y0 is the initial value.
% h is the step size.
% d is the order of the RK method used.
%
% tvals is a column vector with tvals(k) = t0 + (k-1)h, j=1:d
% yvals is a matrix with yvals(k,:) = approximate solution at tvals(k),
% j=1:d
% fvals is a matix with d columns:
% fvals = [f(tvals(d),yvals(d,:)) .... f(tvals(1),yvals(1,:) ]
% i.e., the assembly of the d most recent f snapshots assembled in
% reverse order

tc = t0;
yc = y0;
fc = f(tc,yc);
tvals = tc;
yvals = yc';
fvals = fc;
for k=1:d-1
[tc,yc,fc] = RKStep(f,tc,yc,fc,h,d);
tvals = [tvals; tc];
yvals = [yvals; yc'];
fvals = [fc fvals];
end