function [tout,yout,dt,success]=step(time,y,dt,tol)
global diff;
[t1,y1]=euler(time,y,dt/2);
[t2,y2]=euler(t1,y1,dt/2);
[t3,y3]=euler(time,y,dt);
diff=sqrt((y3(1)-y2(1))^2+(y3(2)-y2(2))^2);
if diff < tol
  tout=t3;
  yout=2*y2-y3;
%  yout=16*y2/15-y3/15;
%  yout=y2;
  success=1;
  if diff < tol/2
    dt=dt*sqrt(2);
  end
else
  tout=time;
  yout=y;
  dt=dt/sqrt(2);
  success=0;
end