% Script to test RK2 integrating routine.
% Written Feb 8, 2008 by Eric Olson for Math/CS 467/667

f=@(y,t) t*t*(y+1);
exact=(0.3+1)*exp(1/3)-1;
steps=[10,25,50,75,100,250,500,750,1000,10000];
for j=1:length(steps)
    Yn(j)=RK2(0.3,0.0,1.0,f,steps(j));
end
En=Yn-exact;
ha=1./steps;
c=polyfit(log(ha),log(En),1);
g=@(x) c(1)*x+c(2);
gvals=g(log(ha));
hold off
plot(log(ha),log(En),'b');
hold on
plot(log(ha),gvals,'g');
hold off
disp(sprintf('slope=%g',c(1)));
