Self.p2 += self.dt * ( -g * l * sp.sin(theta2) + expr6) Self.theta2 += self.dt * (2 * p2 - p1 * expr1) / expr3 Self.theta1 += self.dt * (p1 - p2 * expr1) / expr3 Y2 = y1 - self.length * sp.cos(self.theta2) X2 = x1 + self.length * sp.sin(self.theta2) The generalization to the case of multiple variables is trivial, and a possible implementation of this procedure for our equations of motion may look like the following: Hence, we will restrict ourselves to solely the initial values of the two angles and - or theta1 and theta2 - as we will refer to them in our code.Īnother parameter that we need to supply is the length of the time step $latex\text t$ from the value at time by simply approximating the value of the derivative by a fraction: This would correspond to picking up the pendulum, and releasing it without giving it any nudge. However, we may choose to always start from a state in which the initial velocities are zero. What parameters do we need to supply in order to initialize the pendulum? From a physical point of view, there are four first-order differential equations to be solved, which means we require four initial conditions. Since our pendulum, as a physical system, is associated with both some data (parameters such as the lengths and masses) and some behavior, it makes sense to define a Pendulum class: I will be using Python 3, but the code can be adapted for Python 2 with only minor changes. We will now write a Python program that will solve the above equations numerically and plot the motion of the double pendulum. We will assume that the lengths of the two pendulums are identical and equal to one. The implementation of the full, general case will be left as an exercise for the motivated reader (I used to hate this sentence with a passion, but I am slowly starting to see the point :). Let us do some assumptions about the lengths and masses of the pendulums in order to simplify the system. While we could directly simulate the above equations, we will not. Let’s go!Īs we have found last time, the system is described by a set of four first order differential equations, two per each degree of freedom: In this part, we will adopt a few simplifications, write a Python script to simulate the system, and animate the motion of the double pendulum. We did this because these equations are a set of first order differential equations in a form that is very conducive to a numerical solution. In the previous instalment, we slogged through the derivation of Hamilton’s equations of motion for the double pendulum.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |