
%f = @(t,y) [y(2), -y(1)];
%y = [1, 0];
%exact = @(t) cos(t);

f = @(t,y) -y;
y = 1;
exact = @(t) exp(-t);

t0 = 0;
tend = 10;

np = 6;
m = 2^np;
t = linspace(t0, tend, m+1);
h = (tend - t0)/m;

sol = zeros(m+1,1);

sol(1) = y(1);
for i = 1:m
    y = rk2step(f, h, t(i), y);
    sol(i+1) = y(1);
end

plot(t, sol, 'ro-');
hold on
plot(t, exact(t), 'b-');
grid on
