Saturday, June 28, 2014

Matlab solar system trajectory simulation

I wrote some code to simulate the trajectory of an object through a grossly simplified version of the solar system.  It uses the ordinary differential equation solver that comes with Matlab, some Newtonian physics, only has the Sun, Earth and Moon, and only uses idealized, circular orbits for those.  The code is here in this github repository:

It's kind of fun to play with and someday I'd like to make an interactive web browser version of it, using perhaps this javascript library for numerical calculations:

Update - important note:  I have subsequently learned about the problem of energy drift which is when using basic differential equation solvers on even simple Newtonian systems, the result will have the system's energy increasing over time - sometimes even exponentially!  There are another class of differential equation solvers (Verlet Integration, Sympletic Integrator) that address this problem, the solar system trajectory code above should be updated to use these instead.