# NDSolve: How to perform a reverse integration consistency check?

Let there be the following NDSolve code:

s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]


I think it may be a usefull idea to use as a constistency check the "reverse" NDSolve i.e. define

fy[x_]:=First[Evaluate[y[x]/.s]


then integrate backwords

revs = NDSolve[{ry'[x] == ry[x] Cos[x + ry[x]], ry[30] ==fy[30] }, ry, {x, 30, 0}]


and finally check whether one is back at the initial point

  revfy[x_]:=First[Evaluate[ry[x]/.revs]

error=Abs[revf[0]-1]/1


However this is a time consuming approach.

Can NDSolve do this automatically (integrate from 0 to 30 and then backwords form 30 to 0)? Is there an equivalent error estimate?

## 2 Answers

Is this what you want?

NDSolve[{y'[x] == y[x] Cos[Sign[30 - x] x + y[x]], y[0] == 1}, y, {x, 0, 60}]
%[[1, 1, 2]][0] - %[[1, 1, 2]][60]
(* 0.0662557 *)


Might be simpler to just use a high working precision and very small step size to assure accuracy:

s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30},WorkingPrecision->50,MaxStepSize->1/5000]


Bet that's pretty close to the actual value at x=30. I've solved them with precision=120 and step size=1/1000000 and accurate upwards to 50 decimal places but takes a while and of course to use high precision, need to input all data to NDSolve likewise with higher precision like changing 0.5 to 1/2 and so forth if possible.