In this project, I aimed to model the motion of a double pendulum with a computer program. Although we can easily predict the trajectory of a single pendulum as a function of time, double pendulums are not analytical and must be modeled discreetly. The double pendulum qualifies as a chaotic system. According to chaos theory, the mechanism will express extreme changes in its path based on its starting position as it is very sensitive to initial conditions. To solve the tedious nature of calculating the mechanism’s trajectory by hand, I created an interactive simulation that used a computational form of Euler’s method to estimate the state of the system at each frame and investigate the contraption’s chaotic behavior.
To simulate this system, I created a program using a standard Web stack (HTML, CSS, JavaScript) so that I could display the program on a web page. To make a simple overview of the code, I made the program run all the setup functions before running an infinite loop in which I first perform all physics calculations, display variables on the side graph, and then render a representation of both the graph and the pendulums. To perform physics related calculations, I programmed a “bob” class and created two instances within the main program. Both bobs contained just over 20 variables and constants to control various properties of motion and appearance. The most important variables to the mechanics would be the fulcrum position, string length, mass, angle, angular velocity, and angular acceleration. I had the main program calculate the accelerations of both pendulums before moving each of them accordingly as to minimize over estimation.
To calculate the accelerations, I researched the motion of a double pendulum and read up multiple explanations that used Lagrangian Mechanics with Trigonometry and ended up programming the equation:
this.angularAcc = (-this.gravity * (2 * this.mass + c.mass) * Math.sin(this.angle) - c.mass * this.gravity * Math.sin(this.angle - 2 * c.angle) - 2 * Math.sin(this.angle - c.angle) * c.mass * (Math.pow(c.angularVel, 2) * c.stringLength + Math.pow(this.angularVel, 2) * this.stringLength * Math.cos(this.angle - c.angle))) / (this.stringLength * (2 * this.mass + c.mass - c.mass * Math.cos(2 * this.angle - 2 * c.angle)));
For the top (parent) pendulum and the equation:
this.angularAcc = (2 * Math.sin(p.angle - this.angle) * (Math.pow(p.angularVel, 2) * p.stringLength * (p.mass + this.mass) + this.gravity * (p.mass + this.mass) * Math.cos(p.angle) + Math.pow(this.angularVel, 2) * this.stringLength * this.mass * Math.cos(p.angle - this.angle))) / (this.stringLength * (2 * p.mass + this.mass - this.mass * Math.cos(2 * p.angle - 2 * this.angle)));
For the bottom (child) pendulum.
For Euler’s method, the time step is simply the frame rate. In other words, every frame, the motion calculations are run and applied to each pendulum in order to maximize accuracy. Because the pendulum does not exist in real physical space but rather a computer visualization of it, the acceleration defaults to 0.5 pixels per second squared which roughly aligns with -9.81m/s2 on the screen. Once I rendered the motion of the pendulum, I would add the current position to the path and also graph certain variables on the side depending on the user’s preference (e.g. angle of first pendulum, angular velocity, etc.).
Occasionally through the process, the program displayed some results that were pretty clearly nonsensical, and although I took measures to try and minimize miscalculations, some computational issues proved unavoidable.
First of all, Euler’s method is notorious for being inaccurate, or more specifically increasingly inaccurate as time moves forward. Therefore, the computer’s predictions for the angular accelerations stray further and further from the “actual acceleration” as time goes on.
Another limitation of working with a computer is its accuracy when storing numbers. The computer can only accurately process decimal points up to a certain place value. Because the program calculates with radians which work on a smaller scale than degrees, even rounding to a small decimal place could dramatically affect the calculation accuracy over time. We can observe this, for example, if we change the angles of both pendulums to 180º from rest (both pendulums are facing straight up). As the computer works in radians, it must try and approximate π radians as accurately as possible; however, as the computer is not infinitely precise, it has to perform calculations on the rounded number instead, so it ends up losing stability and starts moving after waiting for a while.
As the program runs for longer, especially as the trail accumulates on the pendulum, the computer program begins to run slower, decreasing the frame rate and making the movements of the pendulum slower.
This slowing down does not actually affect the step size of Euler’s method as I made every piece of the program dependent on frame rate (for example the gravity), but it does slightly misrepresent the actual motion of the pendulum compared to the real world.
I ran the pendulum simulation for 10 seconds (simulated seconds, dependent on frame rate). For each run, I started the second pendulum with a different starting angle from 88-92, each one degree apart.
The path of the second pendulum’s bob decays and fades to a pale blue as time passes.
The program contains countless more combinations of starting angles and measured variables that can be tested at thedoublependulum.netlify.app.
As we can see from the different simulated results, the even minute changes in starting conditions will dramatically affect the movement of a double pendulum. Even after just 10 seconds of simulated movement (approximately 500 frames of calculation), the pendulums seem to follow extremely different paths. We can also see that the pendulums start to follow similar paths but diverge at an increasing rate as time goes on. We can observe this both by looking at the decaying trails as well as the value graph to the left. This behavior aligns with the unpredictable (or at least very difficult to predict) nature of a chaotic system. Technically, under chaos theory, the progressing states are not actually unpredictable and are instead deterministic: the motion theoretically contains no randomization (as we can see with the underlying computer program). The trajectories instead prove extremely sensitive to initial conditions, adhering to a Butterfly Effect. We can therefore not predict the motion of the double pendulum without differential equations, as we cannot integrate the existing equations, and depending on how we start the system in terms of mass and angle we can drastically change the equation of motion.
To continue this pendulum project, I could add options to the control panel to graph not only important variables vs. time but also important variables vs. other important variables and try to observe different patterns. I could also incorporate friction and air-resistance. Even though I programmed mass customization into the program, I never tested how different masses affect the state of the double pendulum at certain points in time.
If chaotic systems like the double pendulum are technically deterministic, is anything in the world truly random, or is the universe just a conglomeration of interrelated systems that we do not yet know how to calculate? Do random systems truly exist, or do we just not know all the numbers? Do humans have real free will, or is consciousness simply an abstract existence that experiences the results of a chaotic brain? I would argue that we do have free will because humans defined that term ourselves and we can therefore use it to describe our actions. Additionally, we supposedly have some randomness on a quantum level in this universe (or at least to our knowledge) that we cannot predict.
Some cool patterns I made when I messed up the pendulum masses to make them spin super fast. See what you can create! thedoublependulum.netlify.app