Fill in any place that says `# YOUR CODE HERE` or YOUR ANSWER HERE, as well as your name and collaborators below.
Grading for pre-lecture assignments is all or nothing. Partial credit is available for in-class assignments and checkpoints, but **only when code is commented**.


```python
NAME = ""
COLLABORATORS = ""
```

---


```python
import grading_helper as _test
```


```python
# Space for imports, utility functions, etc.

# YOUR CODE HERE
```

# Double Pendulum

(Adapted from textbook exercise 8.15)

A double pendulum consists of a normal pendulum with another pendulum hanging from its end. For simplicity let us ignore friction, and assume that both pendulums have bobs of the same mass $m$ and massless arms of the same length $\ell$. Thus the setup looks like this:



The position of the arms at any moment in time is uniquely specified by the two angles $\theta_1$ and $\theta_2$.  The equations of motion for the angles are most easily derived using the Lagrangian formalism. The resulting pair of equations are

$$\begin{align}
2\ddot\theta_1 + \ddot\theta_2 \cos(\theta_1-\theta_2) &+ \dot\theta_2^2 \sin(\theta_1-\theta_2) + 2{g\over\ell} \sin\theta_1 = 0\,,\\
\ddot\theta_2 + \ddot\theta_1 \cos(\theta_1-\theta_2) &- \dot\theta_1^2 \sin(\theta_1-\theta_2) + {g\over\ell} \sin\theta_2 = 0\,.
\end{align}$$

These are second-order equations, but we can convert them into first-order ones by the usual method, defining two new variables, $\omega_1$ and $\omega_2$, thus:

$$\dot\theta_1 = \omega_1,\qquad \dot\theta_2 = \omega_2\,.$$

In terms of these variables our equations of motion become

$$\begin{align}
2\dot\omega_1 + \dot\omega_2 \cos(\theta_1-\theta_2) &+ \omega_2^2 \sin(\theta_1-\theta_2) + 2{g\over\ell} \sin\theta_1 = 0\,,\\
\dot\omega_2 + \dot\omega_1 \cos(\theta_1-\theta_2) &- \omega_1^2 \sin(\theta_1-\theta_2) + {g\over\ell} \sin\theta_2 = 0\,.
\end{align}$$

Finally we have to rearrange these into the standard form with a single derivative on the left-hand side of each one, which gives

$$\begin{align*}
\dot\omega_1 &= - {\omega_1^2\sin(2\theta_1-2\theta_2) + 2\omega_2^2\sin(\theta_1-\theta_2) + (g/\ell) \bigl[ \sin(\theta_1-2\theta_2) + 3 \sin\theta_1 \bigr]\over 3 - \cos(2\theta_1-2\theta_2)}, \\ \\
\dot\omega_2 &= {4\omega_1^2\sin(\theta_1-\theta_2) + \omega_2^2\sin(2\theta_1-2\theta_2) + 2(g/\ell) \bigl[ \sin(2\theta_1-\theta_2) - \sin\theta_2 \bigr]\over 3 - \cos(2\theta_1-2\theta_2)}.
\end{align*}$$

(If you want to try deriving it yourself, this last step involves some trigonometric identities.)

These two equations, along with the equations $\dot{\theta}_1=\omega_1$ and $\dot{\theta}_2=\omega_2$, give us four first-order equations which between them define the motion of the double pendulum.

1. Write a program to solve the equations of motion from $t=0$ to $t=60$ seconds for the case where $\ell=0.4$ meters, with the initial conditions $\theta_1=\theta_2=\pi$ rad, $\omega_1=0$, and $\omega_2=0.001$ rad/s.


2. The mechanical energy of the system is given by

  $$E = m\ell^2 \bigl[ \omega_1^2 + \tfrac12 \omega_2^2 + \omega_1\omega_2 \cos(\theta_1-\theta_2) \bigr] - mg\ell(2\cos\theta_1 + \cos\theta_2)\,.$$

  Calculate the total energy of the system assuming that the mass $m=1$ kg, and make a graph of energy as a function of time from $t=0$ to $t=60$ seconds. Store the energy in an array named `E`. Before you move on, make sure that energy is conserved.


```python
%%graded # 10 points

# YOUR CODE HERE
```


```python
%%tests

_test.similar(E, 11.76*np.ones(len(E))) # E should be constant
```

Make an animation of the motion of the double pendulum that moves in real time (i.e. your animation should be 60 seconds long).

> Make sure that every time step in your animation is the same size. The motion of the pendulum should be smooth.


```python
%%graded # 10 points

# YOUR CODE HERE
```

2dc74c961f46d63528a14390aa7027c8a0e8a16c
ipynb
Jupyter Notebook
Assignments/10.5 Checkpoint - Double Pendulum.ipynb
davidnero/phys1321-lectures
328222be3de1d68de531f0cc008a6607032e6721
BSD-4-Clause-UC
Assignments/10.5 Checkpoint - Double Pendulum.ipynb
davidnero/phys1321-lectures
328222be3de1d68de531f0cc008a6607032e6721
BSD-4-Clause-UC
Assignments/10.5 Checkpoint - Double Pendulum.ipynb
davidnero/phys1321-lectures
328222be3de1d68de531f0cc008a6607032e6721
BSD-4-Clause-UC
Qwen/Qwen-72B
1. YES
2. YES