Celestial Mechanics on a Graphing Calculator
The Runge-Kutta algorithm goes haywire when the curvature of the orbit becomes very large. The remedy is to build into the algorithm a test of how fast the velocity vector is turning; if it would change too much in one step, you decrease the step size (by one half, in this implementation) and try again. Now you do not specify the number of steps, but only a tolerance on how much change in the angle of the velocity vector you will allow in one step. On the other hand, when the velocity vector is not turning much (here, less than one-half the tolerance), you allow the step size to grow (here, by a factor of 2). In this way the algorithm is adapted to the problem.
More eccentric orbits require tighter control on the velocity vector rotation. For w0=.05 the adaptive Runge-Kutta with rotation tolerance .1 loses control. Taking rotation tolerance .01 does the job.
With w0=.05 the orbit is so eccentric that it passes within 1 pixel of the ``sun.'' The program with tolerance .01 takes quite a few minutes to run; but running the whole algorithm at the minimum step size would involve over 2 million steps.