For no good reason other than curiosity I wrote a small and simple orbit simulation applet. I hesitate to even present it here since the interface is completely non-interactive. The math behind it is as simple as possible - it just sums the gravity acting on each body for each timeslice.

What you are seeing is Mars' larger moon Phobos in grey in the center of your screen. A smaller moon in blue orbits it. In reality neither Phobos, nor any other moon in our solar system, has any moon orbiting it. In spite of that I was curious of a moon of a moon in this case would be stable. It's within the hill sphere, and it is is stable.

The jar file may also be run as a Java application:

    java -jar orbitsym-0.9.1.jar xml/planets.xml

Edit the xml/planets.xml file included in the jar file to change the characteristics of orbiting things. The source code, which is covered by the GPL license version 2 or later, is included in the JAR file. See the "README" included in the jar file for additional information.

Here it is: