This code is really just a wrapper.
The variables are similar to the ones used in the previous Runge Kutta subroutine:
rkck
to be called by rkqs
will return a new value
yscal.
This new scaled error is then going to
be compared to eps stands for.
As most other codes discussed in this lecture notes the action here begins by checking that the dimensions of variables passed to the subroutine are correct. The dimension of y that is extracted is discarded:
ndum=assert_eq(SIZE(y), SIZE(dydx), SIZE(yscal), 'rkqs')
Then the step size
is set to the suggested
step size of htry:
h=htryand we enter the
DO loop within which we
rkck to evaluate the next
y for the suggested value of yerr:
CALL rkck(y, dydx, x, h, ytemp, yerr, derivs)
errmax=MAXVAL(ABS(yerr(:)/yscal(:)))/eps
IF (errmax <= 1.0) EXIT
observe that since we are working with the system of
equations here, and each equation is going to have
its own different value of error
DO loop.
htemp=safety*h*(errmax**pshrnk)
h = SIGN(MAX(ABS(htemp), 0.1_sp*ABS(h)), h)
xnew = x+h
IF (xnew == x) CALL nrerror('stepsize underflow in rkqs')
After we have finished with the looping and have the new
values of
y as well as the new value of error,
we suggest stretching
,
but by no more than 5 times:
IF (errmax > errcon) THEN
hnext=safety*h*(errmax**pgrow)
ELSE
hnext=5.0_sp*h
END IF
The last three lines move the used
into hdid,
the new value of
y goes into y, and
x itself becomes updated to
:
hdid=h x=x+h y(:)=ytemp(:)
The subroutine rkck is going to be very similar to
subroutine rk4, but instead of making just one
Runge-Kutta step, it has to make
ytemp and the observed error
in yerr.
I leave it to you to develop your own version of rkck.
The easiest way to do that is to rewrite subroutine rk4,
which we have discussed in section 4.4.1.