# Wire Bead Toys with Mathematica

These are toys that I loved as a kid. It’s a dead simple toy, but it’s fun to flick a bead and watch it coast along the track. So what are the mathematics of this? What are some properties of it, and how can you simulate and animate it with Mathematica?

There are two solutions. There’s the smart solution, and there’s the brute force solution. The smart solution is easier to do and gives you more intuition towards the problem, but the brute force solution is easy to plug in to mathematica!

# Running Khan Academy Javascript Code Offline

I’ve found that a common question on the Khan Academy javascript computer science tutorials is: “How can I run this code offline?!”

It turns out it’s pretty easy using a little bit of html and a little bit of extra javascript. I explain more in my youtube video on the subject, but for a quick how-to:

2. extract the files to a folder on your computer
3. modify myCode.js, making use of the extra commands “size” and “framerate”, and leaving the first and last line. (also, downloading and replacing any images you use)
4. right click processing.html and select open with and your browser.

This is the exact code that I used for my gravity app. Now you can switch between khanacademy computer science, and your own offline applications!

# The Three Body Problem

Find the simulation here: http://www.mathandcode.com/gravity/

The two-body problem consists of two objects under gravitational attraction. The attraction force is the newtonian force $$G \frac{M_1 M_2}{d^2}$$, where G is some constant, M is mass and distance is the distance between the two objects.

In the two-body problem, the path of each particle can be solved for explicitly. We can get circles or ellipses, like the earth’s path around the sun, or we can get escape trajectories where the two particles pass by and never collide with each other again, taking the form of hyperbolas and parabolas.

The three-body problem is more difficult though. Three-bodies can cause chaos, and you can’t solve it explicitly for hyperbolas/parabolas. The only way to solve the general case is to simulate the system over time.

It’s hard to get to grips with the chaos of the three body problem, but this program tries to depict it.

It starts out with three bodies with the same mass/radius and sends them off in different velocities. From this, you can calculate the future path of the particles. This program shows the path of three objects over the full simulation, so instead of viewing three circles (the particles current positions), you see three lines (the particles paths given the starting conditions). As the initial velocity varies over time, the paths vary, and you get chaotic looking results.

# Gravitational Simulation

http://mathandcode.com/programs/javagrav/

Gravitational simulations can use a lot of processing power. This simulation, written in Java, simplifies it a bit by using a structure called a quadtree. Check out the program page for more information!

The results of the program are pretty awesome. I can simulate about 13,500 particles with universal gravitational attraction in real time.