Computing Gravity: Formula for Average Acceleration

In summary: It can be difficult to optimize and is often too slow for problems with high rates of change. Additionally, the scheme is prone to instability (due to its implicit time integration).
  • #1
Alkatran
Science Advisor
Homework Helper
959
0
I'm attempting to make a program which simulates the gravity of bodies in space. However, I've run into a problem:

The program takes the acceleration/speed/position at a certain time and calculates the new values a (small value of time) later. However, this doesn't work because when two masses get VERY close together:
-The program ees that they are VERY close and gives them a MASSIVE acceleration.
-This results in the planets ending up far away from each other in the next frame.
-Energy isn't conserved and the whole thing is useless.

I was just wondering if anyone had the formula for average gravity over a distance over a period of time. I can make a basic formula for average acceleration assuming the planet continues moving the same speed through the distance. However, the planet will change velocity, so it still won't be accurate at very close distances.
 
Physics news on Phys.org
  • #2
You could maybe put conservation of energy in as a constraint on the program.
 
  • #3
Well, I don´t know how good you are at programming or how simple/sophisticated your program is going to be but if you treat your planets as spheres with a radius instead of pointsize particles you can either

a) add a collision detection. Regardless of what happens on collision (bounce off, stick together, break up, ...) the distances between the planets should always be big enough to avoid your problems. If you still have probs you can either make your timesteps smaller od switch to a better intergration method (simple forward steps are the most basic integration method).

b) Let the planets pass through each other but calculate the force acting on them correctly. F=0 for d(istance)=0, for example. Too lazy to calculate it out now and maybe you can well do that yourself. Intuitively it should be F=a*d + b*d for d<r1+r2 where a and b are typical constants for the planets.

EDIT: On 2nd though option b) seems rather stupid (what would your planets be, then? Crystalline gas?)
 
Last edited:
  • #4
You might want to have an adaptive time step. The program might use smaller time steps when the accelerations appear to be large. In other words, you first calculate the acceleration with the current time step. If that acceleration is very large, you halve the time step and try again. If, on the other hand, the acceleration is very small, you double the time step and try again. In this way, the program will never allow the acceleration to be change more than a certain amount from one frame to the next.

- Warren
 
  • #5
While walking to the cinema earlier this evening I came up with an other alternative which would be my favorite atm:
When gravitational force between two objects exceeds a certain very large number of your choice:
Unless you accidentially have 3 bodies coming close to each other at the same time you can assume the force they exert on each other exceeds the forces from all other objects by far => neglect them => 2-body problem. The 2-body problem can be solved analytically so as long as both objects are within your critical range you move them along the trajectories of the 2-body problem. Once they get out of the critical range you proceed with your normal procedure. The error should be insignificant. You can even treat your objects as point-masses, then.
 
  • #6
These are all excellent logical ideas... the only problem is it's the type of solution I already had! (For example, the radius limitation was the current solution)

I suppose my real question is:
Assuming you know the inital speed, initial force, final force, distance, and time, can you calculate final speed or acceleration?
 
  • #7
I don't know how your program is done, but a common pitfall is to simply add up delta-Vs (or delta-Accelerations, or whatever delta) instead of integrating them for the timeframe. If the acceleration is a function of distance, and youv'e got a large acceleration due to close distance, AND you apply the same CONSTANT force through the next timeframe (incorrect), then your planets end up far away. If, instead, the result of the force is an integral of the acceleration over time (where the acceleration itself is a FUNCTION, probably a decreasing one), then maybe you get close to the real thing.
This is just general advise; the actual math should be shown by somebody else. :-p . Hope this helps, anyway.
 
  • #8
Alkatran said:
I'm attempting to make a program which simulates the gravity of bodies in space. However, I've run into a problem:

The program takes the acceleration/speed/position at a certain time and calculates the new values a (small value of time) later. However, this doesn't work because when two masses get VERY close together:

You should do some web searches for "numerical integration" and "runge-kutta" for a starter.

link

will at least get you somewhat started.

Runge-kutta, in spite of being one of the standard workhouse schemes of numerical integration, isn't necessarily the best choice for large gravity simulations, though. But it's probably a good enough to "play around" with. You'll need an adaptive timestep to deal with close approach, too.
 
  • #9
Dodo said:
I don't know how your program is done, but a common pitfall is to simply add up delta-Vs (or delta-Accelerations, or whatever delta) instead of integrating them for the timeframe. If the acceleration is a function of distance, and youv'e got a large acceleration due to close distance, AND you apply the same CONSTANT force through the next timeframe (incorrect), then your planets end up far away. If, instead, the result of the force is an integral of the acceleration over time (where the acceleration itself is a FUNCTION, probably a decreasing one), then maybe you get close to the real thing.
This is just general advise; the actual math should be shown by somebody else. :-p . Hope this helps, anyway.

Yes, I knew that was the problem. But I couldn't figure out how to do it with high-school maths.
 

FAQ: Computing Gravity: Formula for Average Acceleration

What is the formula for average acceleration?

The formula for average acceleration is a = (vf - vi) / t, where a is the average acceleration, vf is the final velocity, vi is the initial velocity, and t is the time interval.

How is average acceleration related to gravity?

Average acceleration is related to gravity through the formula a = g, where g is the acceleration due to gravity. This means that in the absence of other forces, an object will accelerate towards the ground at a rate of 9.8 m/s2 due to the force of gravity.

What are the units for average acceleration?

The units for average acceleration are meters per second squared (m/s2). This represents the change in velocity per unit of time.

How can the formula for average acceleration be used to calculate the force of gravity?

The formula for average acceleration can be rearranged to a = F/m, where F is the force and m is the mass of the object. By substituting a = g and m with the mass of the object, we can calculate the force of gravity acting on that object.

Can the formula for average acceleration be used for objects falling at different heights?

Yes, the formula for average acceleration can be used for objects falling at different heights. As long as the initial and final velocities are known, the formula can be applied to calculate the average acceleration of the falling object regardless of the height.

Similar threads

Replies
13
Views
619
Replies
6
Views
3K
Replies
5
Views
2K
Replies
7
Views
1K
Replies
73
Views
22K
Replies
12
Views
3K
Replies
8
Views
2K
Replies
17
Views
2K
Back
Top