Live data from Hacker News

Double Pendulum in fewer than 100 lines of JavaScript

physicsandbox.com

41–50 of 55 posts

Re: Double Pendulum in fewer than 100 lines of JavaScript

#41
The Nature of Code by Daniel Shiffman is a free (pay what you want) open source ebook about simulating natural systems.

The first five chapters are about physical systems like this pendulum while the remaining chapters are mostly AI related.

The book use Processing but the concepts are language agnostic: http://natureofcode.com/book/

Re: Double Pendulum in fewer than 100 lines of JavaScript

#43

Interesting thing about the double pendulum - it is very difficult to get the numerical integration correct, even using very high order integrators like RK4. The simple Euler integrator used here has no hope of getting it right (not a criticism, just an observation!) The problem is that the double pendulum equations (in fact, any equations of motion derived from a Hamiltonian) have symplectic structure, i.e. they hav…

Leapfrog integration will also get you conservation of energy.

See this thesis: http://umu.diva-portal.org/smash/get/diva2:140361/FULLTEXT01...

the basis for this awesome physics simulator: http://www.algodoo.com/

Conservation of the hamiltonian with leapfrog integration is also the principle behind Hybrid Monte Carlo methods http://www.mcmchandbook.net/HandbookChapter5.pdf

Re: Double Pendulum in fewer than 100 lines of JavaScript

#44
post #5

Earlier quoted context omitted.

Me too. Lagrangian mechanics are almost the only thing about my physics undergrad where I still recall thinking "wow this is awesome!"

Where can I find a good introduction to Lagrangian mechanics?

We used a combination of Goldstein (a classic as another poster pointed out) and Marion & Thornton's Classical Dynamics of Particles and Systems (which was good but not great).

Re: Double Pendulum in fewer than 100 lines of JavaScript

#45

Interesting thing about the double pendulum - it is very difficult to get the numerical integration correct, even using very high order integrators like RK4. The simple Euler integrator used here has no hope of getting it right (not a criticism, just an observation!) The problem is that the double pendulum equations (in fact, any equations of motion derived from a Hamiltonian) have symplectic structure, i.e. they hav…

Leapfrog integration will also get you conservation of energy. See this thesis: http://umu.diva-portal.org/smash/get/diva2:140361/FULLTEXT01... the basis for this awesome physics simulator: http://www.algodoo.com/ Conservation of the hamiltonian with leapfrog integration is also the principle behind Hybrid Monte Carlo methods http://www.mcmchandbook.net/HandbookChapter5.pdf

That thesis looks insteresting, but is also 472 pages. Is there a TL;DR version?

Re: Double Pendulum in fewer than 100 lines of JavaScript

#46
post #33
post #9

Earlier quoted context omitted.

I did basically this in my first year of college! See [1]. (Note: code was never intended to be visible to the public, and this is old and bad. But hey, it works!) http://kevingibbons.org/doublependulum.html

Your simulation has a "Daming factor"

... Well that's an ancient typo. Corrected, thanks.

Re: Double Pendulum in fewer than 100 lines of JavaScript

#47
post #5

Earlier quoted context omitted.

Me too. Lagrangian mechanics are almost the only thing about my physics undergrad where I still recall thinking "wow this is awesome!"

Where can I find a good introduction to Lagrangian mechanics?

I love how everyone has their favorite Classical Mechanics text and how they are almost all very different, though Goldstein and Marion almost always top the lists.

I learned from a less established text by Taylor: http://www.amazon.com/Classical-Mechanics-John-R-Taylor/dp/1...

Looks unavailable, but a PDF is very clearly the second result on Google for "Classical Mechanics Taylor" so it may be a good option for the tight budget :)

Re: Double Pendulum in fewer than 100 lines of JavaScript

#48
post #3

Cool. Feature request: mount the pivot on a programmable cart. It'd be fun to write software to balance the double pendulum. e.g. https://www.youtube.com/watch?v=B6vr1x6KDaY and, balancing a triple pendulum: https://www.youtube.com/watch?v=cyN-CRNrb3E

I feel like we ought to be burning someone as a witch after watching that.

Re: Double Pendulum in fewer than 100 lines of JavaScript

#50
post #26

Earlier quoted context omitted.

For me, the most interesting part of Chaos is that it is deterministic.

Meh, it's mathematically deterministic. In reality there is always error (modelling error, measurement error, simulation error) which means that chaotic systems are effectively random on long time scales, even though they are technically deterministic.

I would disagree with the phrase "effectively random" because its too general. Chaotic attractors survive the presence of noise and Chaotic systems look nothing like random data when viewed in a certain way.

Another way of looking at real systems, is that the system is deterministic and the errors are random.

Post reply on HN