Shooting Blocks

A video on Veritasium’s channel gave a problem which seems to trip up a lot of people! (I got it wrong too)

In the end, it comes down to simple conservation of momentum, and nothing needs to be said about energy. If the sum of all forces adds up to zero, or to gravity’s pull on earth’s surface, then momentum is conserved, or decreases at a rate according to gravity, and so the time when the total momentum is precisely zero will always be the same regardless of where the block hits it. That is, if \(\sum p_{t_0}=a\) (sum of the momenta at time zero is \(a\)), and all the forces obey Newton’s third law except perhaps gravity, that is,  \(\sum \dot{p}_{t}=-gM\), then the time when the total momentum is zero is simply \(a/(gM)\), and this is the same, allowing the center of mass of the bullet-block system to travel the same distance every time, regardless of the initial offset of the bullet.

But that’s no fun, what’s more fun is to analyze the dynamics of it! Energy loss! Bullet penetration depth! I made a simple model of the system where I treated the interaction between the bullet and the block as a velocity-proportional friction force, and made an applet and wrote some Mathematica code to boot!

We can see that, indeed, when the bullet hits dead center, more energy is lost to heat, but the bullet penetrates further.

Offset vs Penetration Depth

Offset vs Energy Lost

Neat dynamics? Check. Neat app? Check. Neat youtube video response? Sorry, my editing software died horribly after a re-install. Have fun with the javascript app!

Wire Bead Toys with Mathematica

 

Sliding Bead Toy

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

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:

  1. download http://mathandcode.com/kacode/khancode.zip
  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.

Abstract Gravity Plot

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.