3 ms·
One of the first programs I ever wrote was a simulator for a planet rotating a star with a naive difference equation approximation to Newton's law. I was a bit
by joe_the_user 3y ago
One of the first programs I ever wrote was a simulator for a planet rotating a star with a naive difference equation approximation to Newton's law. I was a bit disappointed to see the planet reliably spiral into the sun.
The main thing is that something like Euler's method (naive iterative approximation) doesn't guarantee conservation of energy. I believe that this is why planetary dynamics are usually handled with Lagrangian equations rather than the naive approximation approach.
Edit: It would be nice to see what the author's system does for two bodies as a sanity check. Three body system was indeed chaotic but still conserve energy - would this system do that?
https://en.wikipedia.org/wiki/Lagrangian_mechanics https://en.wikipedia.org/wiki/Lagrangian_mechanics
- zokier 3y agoIt's true that Euler integration is about as crude as you can get, but you don't need to reach to Lagrangians for improvement; something like Verlet integration can already bring dramatic gains with fairly small changes needed.
- _0ffh 3y agoYes, I think it's probably the simplest symplectic method, which would be quite the improvement already.
- forgotpwd16 3y agoCan convert Euler's method to a symplectic integrator utilizing v_{n+1} when computing x_{n+1}. That said although such integrators are widely used (usually of higher order than Euler's) in celestial mechanics, one is not restricted to them. For example Bulirsch-Stoer is also very used even if it isn't symplectic because remains accurate (energy error very low) even on long integrations.
- FredFS456 3y agoI think symplectic integrators are typically used, which are derived from hamiltonian mechanics https://en.wikipedia.org/wiki/Symplectic_integrator https://en.wikipedia.org/wiki/Symplectic_integrator
- dekhn 3y agoIt wasn't the first program I wrote, or even a program I wrote, but in middle school a friend wrote a 3-body integrator in BASIC (sun, earth, moon). That single 20 line program shaped my entire world view for a long time (decades), implying to me that we could, if we had powerful enough computers, simulate all sorts of things... even entire universes (which was also an idea that I explored with cellular automata). It's not a particularly helpful worldview and can often be harmful if you're working with complex systems, or systems that require more than o(n(log(n)) per step, or any number of other real-world problems scientists face. Many years later I was impressed at how well astronomy packages work (IE, "it's time T at local L, what is the angle of the sun in the sky?") and stumbled across this paper by Sussman: https://web.mit.edu/wisdom/www/ss-chaos.pdf https://web.mit.edu/wisdom/www/ss-chaos.pdf which shows some pretty serious work on future prediction of solar system objects.
- forgotpwd16 3y ago>simulate all sorts of things... even entire universes You also assumed that chaos is a measurement problem. You could simulate entire universe if you knew the initial conditions sufficiently enough. There were two nice recent papers[1][2] that showed in order to predict some orbits you'll need an accuracy less of Planck length or else some systems are fundamentally unpredictable. [1]: https://arxiv.org/abs/2002.04029 https://arxiv.org/abs/2002.04029 [2]: https://arxiv.org/abs/2311.07651 https://arxiv.org/abs/2311.07651
- dekhn 3y agoI'd love to see convincing evidence that we could simulate the universe using only standard physical laws. IIUC we don't have a way to do that or reliably say whether it's possible. It's also not that interesting a problem because it's so impractical.
- actionfromafar 3y agoBut it would be interesting to see if we could simulate a universe and observe if it in any way resembled ours. Even if the simulated universe was much "smaller". (It would of course have to be.)
- PeterisP 3y agoWould it make sense to explicitly implement conservation of energy? I.e. do a simple method but calculate the total energy at the beginning, and at each step adjust the speeds (e.g. proportionally) so that the total energy matches the initial value - you'll still always get some difference due to numerical accuracy issues, but that difference won't be growing over time.
- comicjk 3y agoThe method you describe would be an example of what is called a "thermostat" in molecular dynamics (because the speed of molecules forms what we call temperature). Such adjustments to the speed can definitely paper over issues with your energy conservation, but you still have to be careful: if you rescale the speeds naively you get the "flying ice cube" effect where all internal motions of the system cease and it maintains its original energy simply by zooming away at high speed. https://en.wikipedia.org/wiki/Flying_ice_cube https://en.wikipedia.org/wiki/Flying_ice_cube
- montecarl 3y agoThermostats ensure that the average _kinetic energy_ remains constant (on average or instantaneously depending on how they are implemented). Your parent post wants to enforce the constraint that the total energy remains constant. So its a bit different from a canonical ensemble (NVT) simulation. This is a microcanonical ensemble simulation (NVE). This means you don't know if you should correct the position (controlling the potential energy) or the velocities (controlling the kinetic energy). Basically, there will be error in the positions and velocities due to the integrator used and you don't know how to patch it up. You have 1 constraint; the total energy should be constant. There are 2(3N-6) degrees of freedom for the positions and velocities (if more than 2 bodies). The extra constraint doesn't help much! Edit: Also, the only reason thermostats work is because the assumption is that the system is in equilibrium with a heat bath (i.e. bunch of atoms at constant temperature). So there is an entire distribution of velocities that is statistically valid and as long as the velocities of the atoms in the system reflect that, you will on average model the kinetics of the system properly (e.g. things like reaction rates will be right). In gravitational problems there is no heat bath.