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


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



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 2


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 *)

enter image description here


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.