/ interactive_tutorials / hamiltonian_systems
Sign in
interactive_tutorials / hamiltonian_systems
hamiltonian_systems / recipe.md
224 lines · 10.3 KBPreviewCodeBlameHistoryRaw
1# Hamiltonian Systems Interactive Tutorial
3The landing page simply says "Introduction to Hamiltonian Systems" with an invitation to click to get started.
5Notes:
6- Each slide should be 1920 × 1080 pixels with a rectangle border
7- The url contains the current page, so reloading the page doesn't bring us back to the beginning
8- Have navigation buttons (next/prev) always at the bottom of each page, and let the arrow keys (left/right) and home/end also control this. This is an interactive slide presentation.
9- There should be two panels. On the left is the text, equations, etc. On the right is the interactive content, diagrams and controls. But some pages start with centered content, and only expand to two panels when the user clicks something.
10- The title of each slide should be at the top and the panels should be independently scrollable.
11- The next and prev buttons should have a single word hint of the content.
12- Start/stop buttons sit in the top-right corner of their diagram, next to a reset button.
13- On the main page, we should have a crafted by human link that takes us to the https://magland.github.io/arewehuman/ app with the appropriate data embedded in the url for the crafting of the recipe.md.
15## Mass on a spring with no friction
17When user clicks, we go to the first (non title page). It shows a mass on a spring with no friction with the text Example 1: Mass on a spring with no friction. We see a representation of a mass on a spring held at a particular position. The user clicks to "start" and we see the motion start. The user can click to stop it as well.
19This is centered at first with no labels and no equations. Users click a button "show details" reveal the two panels with the equations on left and the labeled diagram on the right.
21q - the position of the block measured from rest
22m - the mass of the block
23k - the stiffness of the spring
24p = m * dq/dt - the momentum
26Hooke's law:
27F = -k * q - the force imparted by the spring
29Newton's second law:
30dp/dt = F = -k * q
32The rate of change in momentum is proportional to the position (opposite direction).
34So we have the system relating position and momentum:
36dq/dt = p/m
37dp/dt = -k q
39And the various quantities should appear on the diagram.
41Use two columns for the equations section so that it can fit better, stacking to one on a narrower screen.
43## Conserved Energy
45Title: Total energy is conserved
47In this page, we show the same spring diagram with a start/stop button, and we depict the kinetic/potential/total energy with bars. But we don't want people to feel dizzy. Again, we just show the unlabeled diagram at the center with the kinetic/potential/total bars with a start/stop button and a details button.
49The details are.
51kinetic: p^2/2m and
52potential: 1/2 k * q^2
54They sum up to a constant, the total energy.
56Depict that in the diagram and show the equations below.
58The Hamiltonian is the total energy
59H = p^2/2m + 1/2 k q^2
61Exercise: Prove H is constant by differentiating with respect to it. The user clicks to reveal the solution.
64## Hamilton's Equations
66We write
68H = p^2/2m + 1/2 k q^2
70And in general, Hamilton's equations are:
72dq/dt = \partial H/\partial p
73dp/dt = -partial H/\partial q
75which in this case yields our equations of motion
77dq/dt = \partial H/\partial p = p/m
78dp/dt = -\partial H/\partial q = -kq
80## Spring - phase space trajectories
82On this page, we will show the trajectory through phase space. We will have the diagram again at the top, but this time with only p and q and k labeled, together with initial position q_0. Then below that we will have an axes with q horizontal and p vertical and the q should line up.
84Then user can adjust the initial position, k, and m. These controls go in the left panel, with the diagram and axes in the right panel.
86Keep the axes fixed. Leave a trail and draw the level curve. The starting position should be a slider that lines up with the q.
88## Pendulum with no friction
90Similarly, we will have a diagram at the top with a swinging pendulum. The bob will be on a massless rod at an initial position and again a "Let Go" button. And then a button to reveal the equations of motion and labels on the diagram.
92In this case
94L - rod length
95m - mass of bob
96g - gravitational acceleration
98q = \theta - angular position
99p = m L^2 d\theta/dt - angular momentum
101The Hamiltonian in this case is
103H = p^2/(2 m L^2) - m g L cos \theta (kinetic plus gravitational potential)
105The Hamiltonian system is then:
107d\theta/dt = p/(mL^2)
108dp/dt = -m g L sin \theta
110Exercise: Apply Hamilton's equations to H to derive this system
112## Pendulum phase space
114Again, the pendulum diagram is at the top. Below that we have an axes for q and p. And the user can control the parameters in the same way. But we should also have an initial momentum. And there should be a dropdown that has presets to show the different types of phenomena. The controls go in the left panel, as on "phase space trajectories" page.
116- small swings
117- large swings
118- almost to the top
119- rotation
120- balanced at the top
121- at rest
123## Liouville's Theorem - Spring
125Go back to the block on a spring example in phase space and show a disk of starting points. On play, let them evolve, and compute and display the area somewhere. The idea is to show that the area is preserved. We should also show the spring diagram (no labels), with a bunch of blocks represented as points. The spring itself follows the single simulation started from the center of the disk, not the average of the points (on all three Liouville slides).
127## Liouville's Theorem - Pendulum
129Similar, for the pendulum.
131## Spring with damping
133Same as the "Spring - phase space trajectories" page except we have another parameter, b, a damping coefficient.
135Then we should write out the system (no longer Hamilton)
137dq/dt = p / m
138dp/dt = -kq-(b/m)p
140where we have an additional force
142F = -b dq/dt = -(b/m)p, proportional to the velocity.
144Keep the initial energy's level curve as reference.
146## Example 3: Double pendulum, no friction
148Same as the "Pendulum with no friction" except with a double pendulum with two bobs.
150When user clicks to show details we give
152Left panel:
154definitions for L_1, L_2, m_1, m_2, g, theta_1, theta_2, p_1, p_2.
156p_1 = (m_1 + m_2) L_1^2 d\theta_1/dt + m_2 L_1 L_2 cos(\theta_1 - \theta_2) d\theta_2/dt
157p_2 = m_2 L_2^2 d\theta_2/dt + m_2 L_1 L_2 cos(\theta_1 - \theta_2) d\theta_1/dt
159And we write down the Hamiltonian and then derive Hamilton's equations for this example.
161With \Delta = \theta_1 - \theta_2 and D = m_1 + m_2 sin^2 \Delta:
163H = T + V
164T = (m_2 L_2^2 p_1^2 + (m_1 + m_2) L_1^2 p_2^2 - 2 m_2 L_1 L_2 p_1 p_2 cos \Delta) / (2 m_2 L_1^2 L_2^2 D) (kinetic)
165V = -(m_1 + m_2) g L_1 cos \theta_1 - m_2 g L_2 cos \theta_2 (gravitational potential)
167Hamilton's equations:
169d\theta_1/dt = \partial H/\partial p_1 = (L_2 p_1 - L_1 p_2 cos \Delta) / (L_1^2 L_2 D)
170d\theta_2/dt = \partial H/\partial p_2 = ((m_1 + m_2) L_1 p_2 - m_2 L_2 p_1 cos \Delta) / (m_2 L_1 L_2^2 D)
171dp_1/dt = -\partial H/\partial \theta_1 = -(m_1 + m_2) g L_1 sin \theta_1 - \partial T/\partial \Delta
172dp_2/dt = -\partial H/\partial \theta_2 = -m_2 g L_2 sin \theta_2 + \partial T/\partial \Delta
174where, since T depends on \theta_1 and \theta_2 only through \Delta,
176\partial T/\partial \Delta = (p_1 p_2 sin \Delta / (L_1 L_2) - m_2 T sin 2\Delta) / D
178Try to keep the layout neat
180Right panel:
182The double pendulum with things labeled
184## Double pendulum phase space
186Similar to "Pendulum phase space" slide
188Left panel:
190All the parameter controls, neatly organized. Presets are chosen by energy (low, medium, high: mostly regular, mixed, mostly chaotic), then from a few presets at that energy.
192Right panel
194Top: the double pendulum animation, with a speed-up menu (x1, x5, x10, x50, x100) next to Start, to fill out the phase space faster
196Bottom: The phase space projected onto (left) theta_1 (horizontal) / p_1 and (right) theta_2 / p_2. We see the trajectory on the left and right, and the tail has some coloring to reflect time. No text.
198## Double pendulum Poincare section
200Exactly the same as the previous slide, except the theta_2 / p_2 plot only shows a small dot when the theta_1 crosses zero degrees (pointing down) with positive momentum p_1.
202## Double pendulum dispersion
204Same as the "Double pendulum Poincare section" except we start with a disk of initial points and view how it evolves similar to the Liouville's Theorem slides (but not measuring area).
206## Double pendulum Poincare section explorer
208In this slide we have one slider (the energy level H, with the default masses and lengths) and then one large view of the poincare section (theta_2 horizontal, p_2 vertical), with the boundary of the region allowed at that energy drawn faintly. Here the section is theta_1 crossing zero with theta_1 increasing, so that each point inside the boundary is exactly one state.
210When the user clicks a point inside the boundary, we start the simulation there and fill out the orbit until it is reasonably complete (new dots stop reaching new parts of the plot), or until a cap. User clicks on another point, which stops the current orbit, and we fill out that orbit. Etc. Changing the energy clears the orbits.
212Each orbit is colored by an estimate of its regularity, related to the area of the orbit: a regular orbit lies on a curve (dimension 1) and a chaotic one fills an area (dimension 2). The estimate is the correlation dimension of the orbit's dots. Each orbit gets its own cool color, blended toward red as it goes from regular to chaotic, with a small legend. Hovering the mouse over an orbit lights it up (the others dim).
214Buttons next to the slider:
216- Auto: adds orbits one at a time, each started in the largest empty gap. Pressing it again adds more, filling smaller gaps.
217- GPU fill (only shown if WebGPU is available): starts a few hundred orbits at once, spread over the empty parts, computed in parallel on the GPU.
218- Reset: clears the orbits.
220## Double pendulum - listening to orbits
222Same as last slide, but you can listen to individual orbits.
224Here's the idea. Compute the orbit in full phase space, and compute some linear or nonlinear projection. For example projection onto one of the phase space dimensions. Then turn this into a waveform and listen to the audio. It would need to be sped up so that it is audible. We should have a slider that controls the frequency. Presumably, we can hear the structure of the orbit somehow based on the various frequencies. Would be nice to see a spectrogram as well.
↑↓ move↵openescclose