Day 20, Thursday, April 12, 2018

Planetary motion

One sun

Motion of a planet around a sun



Improved Euler

Runge-Kutta 4th order


Newton's cannon


adaptive step control

Two suns

Prepared notes 1

Prepared notes 2


  1. Please do implement and use RK4 because Improved Euler just won't be accurate enough.

(2) Here is my adaptive step-size selection idea. We want to avoid the velocity changing a lot from one step to the next. This is particularly important when the planet has a close encounter with a sun - the direction of the force of gravity changes very rapidly with position, hence doubly so with time since the planet moves fast when it's close to a sun. The acceleration, which is f(X,t)[2:] happens to hand us exactly how fast the velocity vector is changing. So we can put a cap on the magnitude of the change in velocity over a single step by setting h = c/|| a || for every step ( i.e. c/numpy.linalg.norm( f(X,t)[2:] ) ) where c is some suitably chosen constant. I have found that this works really well, taking lots of steps when passing close to a star and striding out when far away.