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

  • Thread starter Thread starter DivergentSpectrum
  • Start date Start date
  • Tags Tags
    Error Measure
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
 
Thread 'Direction Fields and Isoclines'
I sketched the isoclines for $$ m=-1,0,1,2 $$. Since both $$ \frac{dy}{dx} $$ and $$ D_{y} \frac{dy}{dx} $$ are continuous on the square region R defined by $$ -4\leq x \leq 4, -4 \leq y \leq 4 $$ the existence and uniqueness theorem guarantees that if we pick a point in the interior that lies on an isocline there will be a unique differentiable function (solution) passing through that point. I understand that a solution exists but I unsure how to actually sketch it. For example, consider a...
Back
Top