assert_eq
bit, because it's much the same as before.
We begin by evaluating the length of a mid-point step by
dividing our input value of
by nstep:
h = htot / nstepThus
ym = y yn = y + h * dydx x = xs + hSo that at this stage ym = y0 and yn = y1, whereas x = x1.
The next step is to evaluate the right hand side of the differential equation at x1 and y1:
CALL derivs(x, yn, yout) h2 = 2.0_sp * hNow we are ready to start the leapfrog. h2 becomes 2 h and we enter the
DO loop within which:
CALL swap(ym, yn)
yn = yn + h2 * yout
x = x + h
CALL derivs(x, yn, yout)
The last step, just before leaving the subroutine,
is to wind down the process by taking the average
of the implicitly evaluated last value of
y, i.e., ym + h * yout and
explicitly evaluated value, i.e., yn,
and return that average in yout:
yout = 0.5_sp * (ym + yn + h * yout)