[HN Gopher] 5 Steps to N-Body Simulation
       ___________________________________________________________________
        
       5 Steps to N-Body Simulation
        
       Author : dargscisyhp
       Score  : 62 points
       Date   : 2025-05-10 08:10 UTC (2 days ago)
        
 (HTM) web link (alvinng4.github.io)
 (TXT) w3m dump (alvinng4.github.io)
        
       | mclau157 wrote:
       | Very well done!
        
       | antognini wrote:
       | Once you have the matrix implementation in Step 2 (Implementation
       | 3) it's rather straightforward to extend your N-body simulator to
       | run on a GPU with Jax --- you can just add `import jax.numpy as
       | jnp` and replace all the `np.`s with `jnp`s.
       | 
       | For a few-body system (e.g., the Solar System) this probably
       | won't provide any speedup. But once you get to ~100 bodies you
       | should start to see substantial speedups by running the simulator
       | on a GPU.
        
       | umpalumpaaa wrote:
       | Every time I see anything on the N-Body problem I am reminded by
       | my final high school project... I had 2-3 weeks of time to write
       | an n-body simulation. Back then I used C++ and my hardware was
       | really bad (2 GHz single core CPU or so...). The result was not
       | really impressive because it did not really work. :D But I was
       | able to show that my code correctly predicted that the moon and
       | the earth would eventually collide without any initial velocity
       | given to both bodies. I went into this totally naive and blind
       | but it was a ton of fun.
        
       | munchler wrote:
       | In Step 2 (Gravity), why are we summing over the _cube_ of the
       | distance between the bodies in the denominator?
       | 
       | Edit: To answer myself, I think this is because one of the
       | factors is to normalize the vector between the two bodies to
       | length 1, and the other two factors are the standard inverse
       | square relationship.
        
       ___________________________________________________________________
       (page generated 2025-05-12 23:00 UTC)