function ShowRK()
% Plots absolute error for fixed step size Runge-Kutta
% solution to y' = y, y(0) = 1 across [0,5].

close all
a = 1;
E = zeros(5,5);
for i=1:5
n = 16*2^i;
Exact = exp(-a*linspace(0,5,n+1)');
for k=1:5
[tvals,yvals] = FixedRK(@(t,y) f1(t,y,a),0,1,5/n,k,n);
E(i,k) = max(abs(yvals-Exact));
end
end
semilogy([32 64 128 256 512]',E)
axis([0 700 10^-15 10^-1 ])
set(gca,'xtick',[100 200 300 400 500 600 ])
set(gca,'ytick',logspace(-14,-2,7))
set(gca,'yticklabel',[-14 -12 -10 -8 -6 -4 -2])
set(gca,'fontsize',14)
title(sprintf('RK on y''(t) = -ay(t), y(0) = 1, 0<=t<=5, h = 5/n, a = %3.1f',a))
xlabel('n (Number of Steps)')
ylabel('log(Maximum absolute error)')
grid on
legend('k=1','k=2','k=3','k=4','k=5')

function yp = f1(t,y,a)
yp = -a*y;