[Haskell-cafe] Squashing space leaks
Daniel Fischer
daniel.is.fischer at web.de
Mon May 9 05:00:30 EDT 2005
Am Montag, 9. Mai 2005 05:38 schrieb Greg Buchholz:
> Daniel Fischer wrote:
> > One question: the energy of the system should be constant - that little
> > physics I know. What I don't know is whether the change in energy in this
> > simulation is within usual, reasonable bounds or not. If not, is it due
> > to a too long time interval or should one use a more sophisticated
> > algorithm?
>
> The change in energy is from round-off error caused by floating point
> arithmetic. For this particular test, the shootout requires everyone to
> use the same algorithm. So the error is expected.
>
> Greg Buchholz
Well, I think most of the change is due to the algorithm, which gives a rather
crude approximation to the actual solution of the ODE. This is backed by
trying different values of dt (actually tested with Java, because that uses
hardly any memory at all and is much much faster).
For the tests, dt * k = 20, dt is the argument:
dafis at linux:~/Documents/haskell/dmitri/Greg/Bodies> java PlanSys 0.1
-0.1690751638285245
-0.16877178579767274
dafis at linux:~/Documents/haskell/dmitri/Greg/Bodies> java PlanSys 0.05
-0.1690751638285245
-0.16899653420881677
dafis at linux:~/Documents/haskell/dmitri/Greg/Bodies> java PlanSys 0.025
-0.1690751638285245
-0.1690547211965566
...
dafis at linux:~/Documents/haskell/dmitri/Greg/Bodies> java PlanSys 0.00001
-0.1690751638285245
-0.16907516338916015
dafis at linux:~/Documents/haskell/dmitri/Greg/Bodies> java PlanSys 0.000005
-0.1690751638285245
-0.16907516360969982
dafis at linux:~/Documents/haskell/dmitri/Greg/Bodies> time java PlanSys
0.0000025
-0.1690751638285245
-0.16907516371932937
real 1m42.464s
user 1m39.900s
sys 0m2.540s
To me it looks like finer granularity on the time scale is not yet consumed by
rounding errors (and since we never divide by small numbers, I wouldn't
expect any dramatic effects for a while).
If the algorithm - including dt - is prescribed, fine, but I wonder what sort
of deviation physicists would consider acceptable.
For dt = 0.01, k = 2000 we have a relative error of about 2*10^(-5), is that
within accepted bounds or not? (Any physicists hang about here?)
Cheers,
Daniel
More information about the Haskell-Cafe
mailing list