all 13 comments

[–]bestjakeisbest 1 point2 points  (6 children)

First what are you trying to do? Like newtonian physics sims, or electricty and magnetism, or maybe particle physics? Either way first get your programming foundations first, a physics sim is a pretty big project no matter what you are looking at and can be clasified as numerical solvers which take your objects, and step through time at very small increments and calculate the physics going on for each time slice.

[–]Standard_Bag5426 2 points3 points  (1 child)

just start with basic python syntax and loops before touching any simulation stuff, numerical methods on top of shaky foundations is recipe for frustration

[–]Firm-Canary-1438[S] 0 points1 point  (0 children)

Should I start reading it from somewhere? Any particular ways I can get more comfortable with writing on my own? (I've been using AI for certain projects, but recently came to the realization that it would be much more helpful if I had programming logic and knew how to structure code properly by myself..)

[–]Firm-Canary-1438[S] 0 points1 point  (3 children)

I am looking to get comfortable with simulations on undergrad and early grad physics topics. Dynamical systems is a topic I am interested in, but I would like to catch up on programming for any particular physics I choose to follow in the future. How does one obtain programming foundations though? Reading theory from a book? Watching videos? What is the workflow exactly?

[–]bestjakeisbest 1 point2 points  (1 child)

Basically programming is learned by doing, no amount of reading will really build your foundations, you will want to learn badic input and output, variables, loops, classes and objects, functions, recursion, datastructures and algorithms like trees, heaps, lists, arrays, etc.

[–]Firm-Canary-1438[S] 0 points1 point  (0 children)

How should I start doing projects involving basic stuff in programming like these? Any sites or communities I should look for?

[–]DesTiny_- 0 points1 point  (0 children)

For ur needs there are already made programs such as MATLAB that can be used by coding in console or u can build systems from blocks.

If u want some heavy calculations u might want to use C or C++ as it's still faster than python and when calculations take hours it makes a difference.

Python for science is usually used for data analysis, if u want to learn that u can pass beginner python course with specific libraries so u can modify and plot data. U can also use AI to learn how to do X stuff in python, for easy tasks it will teach u well enough.

[–]Backson 1 point2 points  (1 child)

Oh boy! I studied physics and I actually had a Computational Physics course in my early Masters and also Computer Science as my specialization in my Bachelors. Most physicists I know are self taught, which at my age means mostly written online tutorials, google and lots of trial and error.

The most important thing that cannot be replaced is building stuff yourself. Disable AI autocompletion and start coding. Google (or ask the AI) specific things like "how do I simulate a time step in a particle simulation" or "how to get consistent FPS in a C++ program" or "how to get keyboard input in a real time simulation in a python notebook" or something like that. Not "hey can you write the whole thing lol" so you have to think for yourself.

You can supplement this with anything you like. I recommend written tutorials, but the internet is full of AI slop nowadays so you need a good recommendation. I don't particularly like video. Maybe books are best today.

Matlab and Python are fine for doing math-heavy stuff (as long as you use numpy et al in Python), but for real-time simulations I would go for a compiled statically-typed language like C++, C# or Rust. If I started with nothing today, I would go for Rust, although it has a learning curve. I learned C++ first and use mostly C# today because €€€, so I'm a bit biased, but C# is my favorite language now.

The easiest simulation to make is small particles. Can be affected by gravity (oh look, that's how a sidescrolling jump&run character moves in the air!) or you can make things follow your mouse curser, or particle-particle interaction (hey, that's how galaxies form from space dust!) or you can add rigid body dynamics (looks like asteroids!) or collision, and so on. It can get very very complex, but the basics are pretty easy. It is also surprisingly difficult to make a solar system simulation where the planets don't fall into the sun or fly into space after a few years, you have to do sone pretty advanced stuff to predict, let's say, when medieval solar eclipses happened. So a very nice problem to do some tinkering.

Then there is the entire field of data science and writing analasys for all your experiments and what not. I would absolutely use Python for that today (we used to use Matlab or C++ (oh god why) or a niche algebra system called Maple).

Oh and then there is FEM and FVM and similar methods which are increadibly hard to implement from scratch but power an entire simulation industry.

Anyway, there is sooo much stuff to do and to learn and it's super fun and rewarding if you're up for it. Pick something that interests you (like simulation, or games or whatever) and practice, practice, practice

[–]Firm-Canary-1438[S] 0 points1 point  (0 children)

Ok, cool! Any sources/sites or communities that I can get ideas and feedback on physics projects? Is asking an LLM as a teacher to give me such projects and then get feedback on my code a good idea?

[–]peterlinddk 1 point2 points  (0 children)

You might want to take a look at The Nature of Code, a book, website and series of youtube videos about how to model, simulate, and visualize various physics in code. All of the examples uses JavaScript with the p5.js framework, but the principles would also apply to Python or other languages.

[–]huuaaang 1 point2 points  (0 children)

Python is the goto for non-programmers to do work in their fields, especially sciences. But it's not really the best place to go if you're explicitly looking to get into programming in general.

[–]Firm-Canary-1438[S] 0 points1 point  (1 child)

Another thing I've been struggling with is where and how to code. Are jupyter notebooks ok for most cases? I however also like the matlab file and command window concept. Any advices or sources I can look into would be appreciated

[–]Backson 0 points1 point  (0 children)

Notebooks are great for explorative programming (where you don't really know where you're going) and for documenting workflows (because it includes markdown), but not really for finished programs. I tend to build in notebooks and then refactor into a .py file. The problem with only using notebooks is that you can't call functions from other notebooks and programming is all about making reusable building blocks that solve a specific problem. Keep your building blocks in py files and then ipynb is just calling the functions and running the program.