# Modeling a Double Pendulum with Python and Sympy

I’ll be honest. This is really just a big reminder for me. You see, I’m going to forget how to do this at some point in the future. So hopefully, when I do an internet search on the double pendulum I will find this post. Really, that makes this sort of like a time machine since I am communicating with the future. Hello, Future Rhett.

# Simple Pendulum

Now for the physics. I want to model a double pendulum, but we need to start with something simpler — like a normal pendulum. For this, I’m going to use Lagrangian mechanics. Oh, you don’t know much about that? Don’t worry, I have you covered.

I need to get a solution, I need the Lagrangian for this system. It’s the difference in the kinetic (T) and potential energy (U).

For this simple pendulum, there is only one degree of freedom. That means I can express everything in terms of single variable with the obvious choice of θ. But it’s not completely trivial to get the kinetic energy in terms of θ. So, instead I will write it in terms of Cartesian coordinates.

Note: the “dot” above the x and y is a way to represent the derivative with respect to time. We also need the potential energy, it would just be U = mgy. Now I can get an expression in terms of θ. Here is a diagram that will help.

This means I can write the following expressions for x and y:

The next part has some maths. Here’s the basic outline.

• Take the time derivatives of x and y (in terms of θ).
• Square these derivatives to get the kinetic energy in terms of θ (and θ-dot).
• Also get the potential energy in…