How to | Check the Results of NDSolve
For most differential equations, the results given by NDSolve are quite accurate. However, because its results are based on numerical sampling and error estimates, there can occasionally be significant errors. When you need to be sure of the quality of a solution, it is a good idea to do some basic checking of the solution.
Comparing a solution computed with WorkingPrecision higher than the default MachinePrecision is often a useful way to check results.
Different solutions may save solution data at different points, leading to differences at these points. To keep these differences no larger than the numerical error in the solution, use InterpolationOrder->All.
Use NDSolve with the default MachinePrecision to compute the solution:
Use NDSolve with WorkingPrecision->22 to compute the solution:
Since errors are often quite small, it is useful to view them on a logarithmic scale. RealExponent is effectively equal to Log10[Abs[x]], but without a singularity at zero, so it is a good choice for viewing differences that might be zero at some points:
The residual for a differential equation is the difference of its left and right sides:
The numerical methods used in NDSolve are designed to keep the residual small at any point. You can plot the logs of the residuals:
As you can see, the numerical errors are significantly smaller when using the higher WorkingPrecision. The trade off is, of course, increased calculation time.
Although in most cases keeping the residual small leads to an accurate numerical solution, this is not always true. A simple example is the Duffing equation: