This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
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:
In[1]:=
Click for copyable input
Use NDSolve with WorkingPrecision to compute the solution:
In[2]:=
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, but without a singularity at zero, so it is a good choice for viewing differences that might be zero at some points:
In[3]:=
Click for copyable input
Out[3]=
The residual for a differential equation is the difference of its left and right sides:
In[4]:=
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:
In[4]:=
Click for copyable input
In[5]:=
Click for copyable input
Out[5]=
As you can see, the numerical errors are significantly smaller when using the higher WorkingPrecision. The tradeoff 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:
In[6]:=
Click for copyable input
In[7]:=
Click for copyable input
In[8]:=
Click for copyable input
Out[8]=