What Should I learn to do N-body simulations?

  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Simulations
Click For Summary

Discussion Overview

The discussion revolves around the concepts and skills necessary for performing N-body simulations, including the mathematical, physical, and programming foundations required. Participants explore various programming languages and libraries suitable for implementing these simulations, as well as the theoretical background needed.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant suggests learning differential equations, classical mechanics, and computational physics, recommending the Open Source Physics library and Java for practical examples.
  • Another participant mentions the importance of understanding various mathematical concepts, including algebra, calculus, and linear algebra, before tackling classical mechanics and programming.
  • There is a discussion about the choice of programming languages, with Java, Matlab, and Python being proposed as options, each with its own advantages and resources.
  • A participant emphasizes the need to understand how to numerically solve differential equations within the chosen programming environment.
  • One participant shares their background as a physics undergraduate and expresses a preference for Python over Java due to familiarity and current constraints.
  • Another participant notes that the term 'N-body simulator' is generic and points to different approaches depending on the forces involved, mentioning optimization techniques like Barnes-Hut and neighbor lists.

Areas of Agreement / Disagreement

Participants generally agree on the foundational knowledge required for N-body simulations, but there is no consensus on the best programming language or specific resources to use. Multiple competing views on the approaches and tools remain present throughout the discussion.

Contextual Notes

Some participants highlight the need for a solid understanding of both the mathematics and physics involved, while others point out the importance of practical programming skills. There are references to specific resources and examples, but no definitive recommendations are made.

Who May Find This Useful

This discussion may be useful for students and practitioners interested in computational physics, particularly those looking to learn about N-body simulations and the necessary theoretical and practical foundations.

Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
What Should I learn in terms of concepts to do N-body simulations ? Is there any books that I can follow in this process ?

Thanks
 
Technology news on Phys.org
Differential equations, Classical Mechanics at the Goldstein undergrad level, Computational Physics and programming in some language.

More specifically, the Open Source Physics library and Java is one way. They have a three body example in java that shows the various known solutions to the problem. They have a book that teaches an intro to computational physics.

Another is Matlab and its collection of libraries and toolboxes. Youll have to search for a book or course that discusses the tecniques to use. Mathworks has many resources and notes on its website to get you going.

Python and Anaconda is yet another route.

There is a lot to learn here. While you could bash your way through some examples you’ll always have a doubt that your sim is correct if you don’t understand the math and physics.

I learned via the java route through a grad course i took based on the OSP book and code. I already knew java quite well so that part was easy and the prof guided us through the hard stuff. The funny part was he didn't fully understand java and the new version of the book switched from using basic to using java.
 
  • Like
Likes   Reactions: BvU, QuantumQuest, Arman777 and 1 other person
Hmm so where should I start ?
 
Take an assessment with what you know.

I'd start with the math:
- Algebra
- Geometry
- Algebra 2 ie trig in particular, series, sequences for Calculus ...
- Calculus 1,2,3
- Differential Eqns
- Linear AlgebraAt this point, you should have a good basis for doing any classical mechanics, E&M Theory and Quantum Mechanics at the undergrad level using all the math you've studied so far.

Then the physics:
- Classical Mechanics

And lastly the programming:
- either Java+OSP or Matlab or Python

Finally, you need to understand the specifics of encoding a set of differential equations to solve for numerically in the environment chosen.

https://www.wired.com/2016/06/way-solve-three-body-problem/
Personally, I'd choose learning Java and using OSP because it's designed for doing computational physics in an academic environment. However, there's a lot to be said for using Matlab too.

https://www.compadre.org/osp/items/detail.cfm?ID=9777
https://stackoverflow.com/questions/5293535/programming-a-3-body-problem-using-matlab
Python I'm not as sure of although its heavily used in Data Science and Machine Learning work, but using Numpy and related libraries you could construct some good simulations and Python is easier to learn than Java.

https://github.com/htx1219/Python/blob/master/222/Three Body Problem.py
Miscellaneous resources:

https://www.newscientist.com/articl...dy-problem-has-over-a-thousand-new-solutions/
https://javalab.org/en/three_body_problem_en/
 
Arman777 said:
Hmm so where should I start ?
With a 2-body simulation...? :smile:

How far along are you in your math learning? Have you had calculus yet?

What programming languages are you most familiar with?
 
  • Like
Likes   Reactions: DrStupid and QuantumQuest
I am a physics undergrad student and this is my last year. I took CM, Diff Eqn. , linear algebra and many more courses.
berkeman said:
With a 2-body simulation...? :smile:
Yes that also came to my mind today. I ll start from there.
berkeman said:
What programming languages are you most familiar with?
python
jedishrfu said:
Finally, you need to understand the specifics of encoding a set of differential equations to solve for numerically in the environment chosen.
Once I did a trajectory for an electron under the lorentz force. I guess this would be more complicated but I ll try.

I can't learn java currently so I ll go with python.
 
  • Like
Likes   Reactions: jedishrfu and berkeman
'N-body simulator' is quite generic. You can do it like this: https://compphys.go.ro/Newtonian-gravity/ for the cases when you have forces acting on large distances, or like this: https://compphys.go.ro/event-driven-molecular-dynamics/ when you have only forces that act a very short distance.

Then the optimization issues appear: using Barnes-Hut, neighbors lists and so on... some things I mentioned on the blog. Unfortunately the associated projects are in C++, not python.
 
  • Like
Likes   Reactions: berkeman

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 19 ·
Replies
19
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K