8.3 Finite difference methods 249
Noting that
x(^1 )(t+h/ 2 ) =
(
x(^1 )(t)+h
2
x(^2 )(t)
)
+O(h^2 ),
we obtain
x(t+h) =x(t)+h+x(^1 )(t+h/ 2 )+O(h^3 ),
which needs to be combined with
x(^1 )(t+h/ 2 ) =x(^1 )(t−h/ 2 )+hx(^2 )(t)+O(h^2 ).
Again, there is a lower truncation error inhfor the velocity. Furthermore, the positions and
the velocities are evaluated at different time steps. If oneneedsx(^1 )(t), this can be computed
using
x(^1 )(t) =
(
x(^1 )(t∓h/ 2 )±
h
2
x(^2 )(t)
)
+O(h^2 ).
The initial conditions can be handled in similar ways and theinaccuracy which arises between
x(^1 )( 0 )andx(^1 )(h/ 2 )is normally ignored. Summarizing, the popular Leapfrog algorithm implies
the evaluation of position and velocity at different time steps. The final algorithm is given by
the following steps
x(^1 )(t+h/ 2 ) =x(^1 )(t−h/ 2 )+hx(^2 )(t)+O(h^2 ),
which is used in
x(t+h) =x(t)+h+x(^1 )(t+h/ 2 )+O(h^3 ),
and finally
x(^1 )(t+h) =x(^1 )(t+h/ 2 )+
h
2
x(^2 )(t+h)+O(h^2 ),
8.3.3 Predictor-Corrector methods
Consider again the first-order differential equation
dy
dt
=f(t,y),
which solved with Euler’s algorithm results in the following algorithm
yi+ 1 ≈y(ti)+h f(ti,yi)
withti+ 1 =ti+h. This means geometrically that we compute the slope atyiand use it to predict
yi+ 1 at a later timeti+ 1. We introducek 1 =f(ti,yi)and rewrite our prediction foryi+ 1 as
yi+ 1 ≈y(ti)+hk 1.
We can then use the predictionyi+ 1 to compute a new slope atti+ 1 by definingk 2 =f(ti+ 1 ,yi+ 1 ).
We define the new value ofyi+ 1 by taking the average of the two slopes, resulting in
yi+ 1 ≈y(ti)+
h
2
(k 1 +k 2 ).
The algorithm is very simple,namely