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:

Click for copyable input

Use NDSolve with WorkingPrecision->22 to compute the solution:

Click for copyable input

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:

Click for copyable input

The residual for a differential equation is the difference of its left and right sides:

Click for copyable input

The numerical methods used in NDSolve are designed to keep the residual small at any point. You can plot the logs of the residuals:

Click for copyable input

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:

Click for copyable input
Click for copyable input
Click for copyable input