How do I accurately measure error in my n-body simulation?

In summary, the error in approximating an integral by Simpson's rule is less than or equal to \frac{1}{90}\left(\frac{b- a}{2}\right)^5M^4 where M is an upper bound on |f(x)| between a and b. For the Runge-Kutt method, the optimal step size is given by (tol*h/(2*|rk4-rk5|))1/4*h.
  • #1
DivergentSpectrum
149
15
sorry for spamming the boards with all these questions lol- i promise this is my last post regarding n body problems. how do i measure error? i can't really find much on this subject. i want to use adaptive stepsize in my n body simulator I am guessing for the n-body problem i base my error on energy and angular momentum:
h(n+1)
∫work dt=KEn+1- KEn
h*n
h(n+1)
∫torque*dt=AMn+1-AMn+1
h*n
of course the integrals would be evaluated using simpsons rule, which is equivalent to RK4 in order.
this gives me 4 equations (actually 4*p where p is the number of particles).
now the way i see it i can do this 2 ways:

the work divided by kinetic energy gained should equal 1, and if the fraction isn't close enough to one i repeat the step.

or work minus kinetic energy should equal zero, so i could find the difference and if it isn't close enough to 0 i repeat the step.

i think both of them have their advantages and drawbacks, for example if i went the subtraction route, then if the difference is really small it doesn't really matter if I am dealing with big numbers.
on the other hand, if i use division i might end up with divide by zero problems.
 
Physics news on Phys.org
  • #2
How you measure "error" will depend a lot on what error you are measuring! You mention "Simpson's rule" for integration and Runge-Kutta fourth order for differential equations. Both of those have well defined error rules:
http://en.wikipedia.org/wiki/Simpson's_rule- The error in approximating an integral by Simpson's rule is
[tex]\frac{1}{90}\left(\frac{b- a}{2}\right)^5|f(\xi)|^4[/tex]
Where [itex]\xi[/itex] is a number between a and b. Since we don't know exactly where [itex]\xi]/itex] is, we can say that the error is less than or equal to
[tex]\frac{1}{90}\left(\frac{b- a}{2}\right)^5M^4[/tex]
where "M" is an upper bound on |f(x)| between a and b.

For the Runge-Kutta fourth order method: Well, that's much more complicated so I will just give the reference:
"Runge-Kutt methods with minimum error bounds" by Anthony Ralston
www.ams.org/.../1962-16-080/S0025-5718-1962-0150954-0/S0025-5718-1962-0150954-0.pdf
 
Last edited by a moderator:
  • #3
well, here I am measuring error in velocity and position using the principles of conservation.

i found runge kutta fehlberg. does anybody have any advice on this?
the optimal step size is given by

(tol*h/(2*|rk4-rk5|))1/4*h
where tol is tolerance rk4 is the answer derived by the 4th order method and rk5 is the answer derived by the 5th order method and h is step size
but I am measuring both velocity and position, and an error in velocity probably doesn't necessarily correspond to the same error in position.
do i just multiply the optimal stepsize by h?
 
  • #4
i implemented rkf45, but its horribly innefficient. the reason being i have only figured out how to implement variable time step for the entire system. if i could use different size time steps for each particle it would be much better, but i think I am just going to revert back to old fashioned rk4 for now
 
  • #5


As a scientist, it is important to accurately measure error in any simulation, including n-body simulations. In order to do so, there are a few methods that can be used. One method is to compare the simulated results to known analytical solutions, if they exist. This can provide a benchmark for the accuracy of the simulation.

Another method is to use the principles of conservation of energy and angular momentum. In your case, you have suggested using the work-energy theorem and the torque-angular momentum theorem. These can be used to check the accuracy of the simulation by comparing the calculated values of energy and angular momentum at each time step to the expected values. Any discrepancies can indicate errors in the simulation.

It is also important to consider the numerical methods used in the simulation. Adaptive stepsize, as you have mentioned, can help improve the accuracy of the simulation by adjusting the step size based on the local error. Additionally, using higher-order numerical methods, such as RK4, can also improve the accuracy of the simulation.

In terms of your proposed methods for measuring error, both the work-energy and the torque-angular momentum approaches have their advantages and drawbacks. It is important to carefully consider the magnitude of the values being calculated and any potential divide by zero problems. It may also be beneficial to compare the results from both methods to ensure consistency.

Overall, accurately measuring error in n-body simulations requires careful consideration of the underlying principles and numerical methods being used. It is important to continuously check and adjust the simulation to improve its accuracy and reliability.
 

1. What is error measurement?

Error measurement is a process of determining the difference between the true value and the measured value of a quantity or data. It helps to evaluate the accuracy and precision of a measurement.

2. How do I calculate error?

Error can be calculated by finding the absolute difference between the measured value and the true value, and then dividing it by the true value. This value is then multiplied by 100 to get the percentage error.

3. What is the difference between accuracy and precision?

Accuracy refers to how close a measurement is to the true value, while precision refers to how consistent and reproducible the measurements are. A measurement can be precise but not accurate, or accurate but not precise.

4. What are the common sources of error in scientific measurements?

The common sources of error in scientific measurements include human error, instrument error, environmental conditions, and systematic errors such as parallax or zero error.

5. How can I reduce error in my measurements?

To reduce error in measurements, it is important to use calibrated instruments, follow proper measurement techniques, and repeat the measurements multiple times. It is also helpful to identify and minimize any potential sources of error.

Similar threads

Replies
56
Views
700
  • Classical Physics
Replies
2
Views
1K
Replies
7
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
  • Introductory Physics Homework Help
Replies
4
Views
571
  • Advanced Physics Homework Help
Replies
1
Views
768
Replies
12
Views
2K
  • Programming and Computer Science
Replies
19
Views
2K
  • Differential Equations
Replies
2
Views
1K
Replies
8
Views
2K
Back
Top