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