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

  • Context: Graduate 
  • Thread starter Thread starter DivergentSpectrum
  • Start date Start date
  • Tags Tags
    Error Measure
Click For Summary

Discussion Overview

The discussion focuses on methods for measuring error in n-body simulations, particularly in the context of adaptive step sizes. Participants explore various approaches to quantify error related to energy and angular momentum conservation, as well as the implications of using different numerical integration methods.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant suggests measuring error based on energy and angular momentum, proposing two methods: using the ratio of work to kinetic energy and checking if it equals one, or calculating the difference between work and kinetic energy to see if it approaches zero.
  • Another participant notes that the choice of error measurement depends on the specific type of error being assessed and references established error bounds for Simpson's rule and Runge-Kutta methods.
  • A different participant mentions using the principles of conservation to measure error in velocity and position, and raises a question about how to relate errors in these two quantities.
  • One participant shares their experience with implementing the Runge-Kutta-Fehlberg method but finds it inefficient, expressing a desire to use variable time steps for individual particles instead of a uniform approach.

Areas of Agreement / Disagreement

Participants express differing views on the best methods for measuring error, with no consensus reached on a single approach. The discussion remains unresolved regarding the optimal strategies for error measurement in n-body simulations.

Contextual Notes

Participants highlight the complexity of measuring error in different quantities (velocity vs. position) and the potential inefficiencies of certain numerical methods, indicating limitations in their current implementations.

DivergentSpectrum
Messages
149
Reaction score
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
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
\frac{1}{90}\left(\frac{b- a}{2}\right)^5|f(\xi)|^4
Where \xi is a number between a and b. Since we don't know exactly where \xi]/itex] is, we can say that the error is <b>less than or equal to</b> <br /> \frac{1}{90}\left(\frac{b- a}{2}\right)^5M^4<br /> where &quot;M&quot; is an upper bound on |f(x)| between a and b.<br /> <br /> For the Runge-Kutta fourth order method: Well, that&#039;s much more complicated so I will just give the reference:<br /> &quot;Runge-Kutt methods with minimum error bounds&quot; by Anthony Ralston<br /> www.ams.org/.../1962-16-080/S0025-5718-1962-0150954-0/S0025-5718-1962-0150954-0.pdf
 
Last edited by a moderator:
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?
 
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
 

Similar threads

  • · Replies 65 ·
3
Replies
65
Views
9K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K