In [1]:
%matplotlib inline

A complete N-body simulation and visualization in 140 characters

The following code is exactly 140 characters long and thus fits into one tweet. It integrates the motion of the Sun and Mars using the IAS15 integrator.


In [2]:
import rebound as r;r.add(["Sun","Mars"]);x=[]
while r.t<9:r.integrate(r.t+.1);x+=[r.particles[1].x]
import matplotlib.pyplot as m;m.plot(x)


Searching NASA Horizons for 'Sun'... Found: Sun (10).
Searching NASA Horizons for 'Mars'... Found: Mars Barycenter (4).
Out[2]:
[<matplotlib.lines.Line2D at 0x1136e42d0>]