# Wire Bead Toys with Mathematica

Posted on March 13, 2013 by

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!

Continue reading →

Posted in Uncategorized |

# Running Khan Academy Javascript Code Offline

Posted on September 22, 2012 by

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!

Posted in Uncategorized |

# The Three Body Problem

Posted on September 19, 2012 by

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.

Posted in Uncategorized |

# Gravitational Simulation

Posted on September 10, 2012 by

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.

Posted in Uncategorized |
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9010627269744873, "perplexity_flag": "middle"}