I am solving an ODE using the Runge-Kutta method 4th order and the integration is backward i.e step size ($h$) is negative. All the references that I have seen consider the positive step size.
Is it ok to change $h$ to $-h$ in Runge-Kutta method or is there any change in sign in $K$ values?
Best Answer
If you have a procedure
that works correctly for positive
h
, then this same procedure also works correctly for negativeh
. Remember that the time step remainsThe only problem that may arise is the control of the loop. If the sampling times are given as array, then the loop
will work independent of the direction of the time sample points.
If the loop control is based on the end time, then
while t < tf
works for positiveh
, for negativeh
one has to switch the sign or includeh
as inwhile 0<(tf-t)*h
.