3.5. Accuracy in Position
Bob: Sure. But before doing that, note that the position error in our
first run is about
, where we had
for the leapfrog. So the Runge-Kutta, for a time step of 0.001, is a
hundred times worse in energy conservation and ten times worse in the
accuracy of the positions, compared with the leapfrog. Then, at a
time step of 0.0001, the energy error lags only a factor ten behind
the leapfrog. Okay, let's go to a time step of 0.00001:
|gravity> ruby integrator_driver2c.rb < euler.in
dt = 1.0e-05
dt_dia = 10
dt_out = 10
dt_end = 10
method = rk2
at time t = 0, after 0 steps :
E_kin = 0.125 , E_pot = -1 , E_tot = -0.875
E_tot - E_init = 0
(E_tot - E_init) / E_init =-0
at time t = 10, after 1000000 steps :
E_kin = 0.554 , E_pot = -1.43 , E_tot = -0.875
E_tot - E_init = 6.41e-11
(E_tot - E_init) / E_init =-7.32e-11
1.0000000000000000e+00
5.9961749187967806e-01 -3.6063469285477523e-01
1.0308069441700245e+00 2.1389511823566043e-01
Alice: The third-order style behavior continues! The energy error again
shrunk by a factor a thousand. Now the leapfrog and Runge-Kutta are comparable
in energy error, to within a factor of two or so.
Bob: The position error of our second run was
,
as we can now see by comparison with the third run. That is strange.
The positional accuracy increases by a factor 100, yet the energy accuracy
increases by a factor 1000.
Alice: Let's shrink the step size by another factor of ten.
|gravity> ruby integrator_driver2.rb < euler.in
dt = 1.0e-06
dt_dia = 10
dt_out = 10
dt_end = 10
method = rk2
at time t = 0, after 0 steps :
E_kin = 0.125 , E_pot = -1, E_tot = -0.875
E_tot - E_init = 0
(E_tot - E_init) / E_init =-0
at time t = 10, after 10000000 steps :
E_kin = 0.554 , E_pot = -1.43, E_tot = -0.875
E_tot - E_init = -1.66e-13
(E_tot - E_init) / E_init =1.9e-13
1.0000000000000000e+00
5.9961755426085783e-01 -3.6063458453782676e-01
1.0308069106006272e+00 2.1389530234024676e-01
Bob: This time the energy error shrunk only by two and a half orders
of magnitude, about a factor 300, but still more than the factor
hundred than we would have expected. Also, with
integration steps, I'm surprised we got even that far. At each time,
round off errors must occur in the calculations that are of order
. Then statistical noise in so many calculations
must be larger than that by at least the square root of the number of
time steps, or
.
Alice: Which is close to what we got. So that would suggest that
further shrinking the time step would not give us more accuracy.
Bob: I would expect so much. But these calculations are taking a
long time again, so I'll let the computer start the calculation, and
we can check later. At least now we are pushing machine accuracy for
64-bit floating point with our second-order integrator; a while ago
it took forever to get the errors in position down to one percent.
I can't wait to show you my fourth-order integrator. That will go a
lot faster. But first let's see what we get here.
. . . . .
3.6. Reaching the Round-Off Barrier
Alice: It has been quite a while now. Surely the code must have run
now.
Bob: Indeed, here are the results.
|gravity> ruby integrator_driver2.rb < euler.in
dt = 1.0e-07
dt_dia = 10
dt_out = 10
dt_end = 10
method = rk2
at time t = 0, after 0 steps :
E_kin = 0.125 , E_pot = -1, E_tot = -0.875
E_tot - E_init = 0
(E_tot - E_init) / E_init =-0
at time t = 10, after 100000000 steps :
E_kin = 0.554 , E_pot = -1.43, E_tot = -0.875
E_tot - E_init = -4.77e-13
(E_tot - E_init) / E_init =5.45e-13
1.0000000000000000e+00
5.9961755488235224e-01 -3.6063458345517674e-01
1.0308069102692998e+00 2.1389530417820268e-01
As we expected, the energy error could not shrink further. Instead,
it grew larger, because the random accumulation of errors in ten times
more time steps gave an increase of error by roughly the square root
of ten, or about a factor three -- just what we observe here.
Alice: Note that the positions now agree to within a factor of
. Once more a factor a hundred more accurate than
the difference between the previous two integrations. Clearly the
positional accuracy of the second order Runge-Kutta is second-order
accurate, like that of the leapfrog.