clear all
f=@(x,y) 3*y+x*x
G=@(x) -2/27-2/9*x-1/3*x.*x+13/540*exp(3*x)
steps=[5,10,20,30,40,80,120,250,350,500];
for m=1:10
% [x,y]=euler(0,-1/20,1,f,steps(m));
  [x,y]=rk2(0,-1/20,1,f,steps(m));
  Y=G(x);
  E(m)=max(abs(Y-y));
end
Xerr=log(1./steps);
Yerr=log(E)';
for m=1:10
  A(m,1)=1;
  A(m,2)=Xerr(m);
end
AtA=A'*A;
AtYerr=A'*Yerr;
AtA\AtYerr
plot(Xerr,Yerr,'r');
