Share Your Experience: Take the 2024 Developer Survey

# Tag Info

## Hot answers tagged physics

### Car crash reaction time

Some of the numbers might seem plucked out of thin air but they aren't Still better have them explained. I can understand 3.6 and even ...
• 56.5k
Accepted

### Simple n-body class in C++

The Great! You're not making the basic beginner error of using using namespace std;! The main() function is only 3 lines of code....
• 23.9k
Accepted

### Planetary simulation in python

Use a vector type to store positions, velocities and forces Instead of writing out all the calculations for the x and y direction separately, consider using a library that provides you with vector ...
• 58k

### Car crash reaction time

I suggest breaking the code into functions, so you can easily import your code into a Python shell and test that your computation is exact (and not just thinking it ...

### Ising model simulation

There are many, many things wrong with your code; I'll list some, and then I advise you to fix as many of them as you can (and more) and then repost a new question with the revised code. First of all,...
• 19.4k

### Simple n-body class in C++

First Of All You are doing a great job as a beginner. I have been programming for 10 years and my code for a long time was much, much less readable that what you have written. That said: What needs ...

### Car crash reaction time

It crashes if user input for speed_ms is not integer If user presses any key before t = input("GO!! ") his reaction time is ...
• 231

### Car crash reaction time

If it's wet, the friction_coefficient will be lower. Which means that Bd will be lower (which is probably wrong). It's ...

### Car crash reaction time

player_1 is read and assigned but never used. If the user misspells wet (e.g. as Wet or as <...
• 76.2k
Accepted

### Simulating a two-body collision problem to find digits of Pi

First, this is an awesome video! Upvoted for that reason alone. :) If n=2, the program finishes within milliseconds, whereas for n=3, it takes a whopping 115 seconds. Do you know about big-O ...
• 19.4k
Accepted

### Simulation of a falling ball

using namespace std; is a bad habit to get into, as it can lead to name-collisions and other issues. It's best to explicitly qualify the names we need where ...
• 11.8k

### Complex scientific formula for nuclear magnetic resonance

I would consider the practice ok in this case. Your variable try appear to be roughly the "ASCII" equivalent of the ones used in the equation. You cite the paper where you got the equations from. (...
• 5,906

### "Do I understand the gravity of the situation?"

I spent quite some time looking at this: High Level I love what you did here, a great showcase of using JavaScript in a powerful way. But from a readability and maintainability perspective, this ...
• 33.2k
Accepted

### Metaballs and Gravity game;

Refactoring code structure As of right now, you have: A struct named Object. A global std::vector<Object> of ...
• 15.8k

### Ising model simulation

I'll build off of Quuxplusone's answer. You have issues with tab. int tab[N]; tab[0] = N-1; tab[N+1] = 0; // out of bounds ...
• 376

### Simple n-body class in C++

Your code is written in a hybrid C/C++ style. For instance your destructor has a delete (I can't find where the corresponding new...

### Simple n-body class in C++

In addition to the other answers: Use unsigned integer type for DIM, Nbody.step, and Nbody.n...
• 405

### High performance physics simulation - core class design

Missing #includes You are using std::vector, but did not #include <vector>. The code ...
• 58k
Accepted

### Calculating a table of deBroglie wavelengths for various electron energies

First, simplify: factor out $C^4$ out of square root: $\lambda(E_k) = h\left/C\sqrt{(\frac{E_k}{C^2}+m_e)^2-m_e^2}\right.$ Simplify even more: factor out $m_e^2$: \\$\lambda(E_k) = h\left/C ...
• 56.5k

### Simple n-body class in C++

In addition to the other answers: The init_data function does not belong in the Nbody class. Nowhere in the definition of the N-...
• 21.3k

### Planetary simulation in python

TL;DR: I created a Github project with everything I suggested and more (like taking all PyGame-related logic away from the Planet class, leaving it only with planet-related logic). Take a look at the ...
• 191
Accepted

### Molecular simulation: Minimum Image Convention

periodic_boundary_int = 5 # size of the periodic box in A temperature_float = 2 # temperature of the simulation Thank you for the first comment, that's lovely, ...
• 28.2k
Accepted

### Calculators for gas law equations

First things first: Do not use namespace std; This is bad style. Create a class to properly encapsulate your code and simplify passing of variables. I would suggest, that you use enumerations to ...
• 4,271
Accepted

### Golf game boilerplate

Some of this is nit-pickery, some is more fundamental: Import Order PEP-8 suggests an ordering to imports. No reason not to use it: Imports should be grouped in the following order: ...
• 12.4k

### Simple n-body class in C++

Use a vector math library Find a suitable library that implements coordinate vectors, so you don't have to implement them as arrays of doubles. Ideally your ...
• 58k

### Simulating a Solar System Using Command-Line Graphics

Finally, I am well aware that the value of the gravitational constant 𝐺 is 6.67408×10−11 and not 0.5, as I have implemented it here; using the correct value of 𝐺 results in a simulation that runs ...
• 14.9k
Accepted

### Simulating the orbits of the Earth, Moon and Sun together in Fortran

This question is an oldie but goodie. Nice work! It really deserves some love. An edit bumped it recently to the front page, and that got me interested in how I’d refactor the program. The Modern ...
• 7,676
Accepted

### C program that finds local acceleration due to gravity (g)

There's no need for the forward declaration of local_g() (especially as it's immediately followed by the definition). But it should be declared with ...
• 76.2k

### VBA functions to calculate sun and moon positions

At a bare minimum declare your variable types when Dimming variables*. If you don't, they're automatically Variant. The VBA ...
• 1,290