% Runge Kutta Fehlberg driver
% Check our Algorithm with book's example (table 5.11 p300 in B&F 9-th ed)

% NEED TO IMPLEMENT rkf.m
hmax=0.25; hmin=0.01; tol=1e-5;
f = @(t,y) y - t^2 + 1; a=0; b=2; y0=1/2;
y = @(t) (t+1)^2-0.5*exp(t);
[ya,ta,ha]=rkf(a,b,y0,f,tol,hmax,hmin);

% printing solution, times and time steps
fprintf('%3s %10s %10s %10s %10s\n','i','t_i','y_i true','y_i','h_i');
fprintf('-----------------------------------------------------------------------\n');
for i=2:length(ta),
 fprintf('%3d %10.7f %10.7f %10.7f %10.7f\n',i-1,ta(i),y(ta(i)),ya(i),ha(i))
end;

% Sample output:
%
% normal termination
%   i        t_i   y_i true        y_i        h_i
% -----------------------------------------------------------------------
%   1  0.2500000  0.9204873  0.9204886  0.2500000
%   2  0.4865522  1.3964884  1.3964910  0.2365522
%   3  0.7293332  1.9537446  1.9537488  0.2427810
%   4  0.9793332  2.5864198  2.5864260  0.2500000
%   5  1.2293332  3.2604520  3.2604605  0.2500000
%   6  1.4793332  3.9520844  3.9520955  0.2500000
%   7  1.7293332  4.6308127  4.6308268  0.2500000
%   8  1.9793332  5.2574687  5.2574861  0.2500000
%   9  2.0000000  5.3054720  5.3054896  0.0206668

