How Do I Check My Results in
Mathematica?
Mathematica is one of the most reliable pieces of software ever
written, and every version must pass a great number of tests before
it is shipped. But no piece of software is perfect, and on the user side there
may always be typos or errors in inputs. Of course, the first line of defense
against incorrect results is common sense. For example, one should always ask:
Is the order of magnitude plausible? Is the result plausible?
Additionally, there are some simple tests you can do in Mathematica
to check your results without a lot of effort. In more complex cases, more
complex tests might be necessary.
Substitute the Result Back into the Problem
In many cases, you can simply put the result back into the original problem
and see if the result really solves the problem.
For example, take the result to this well-known problem.
![[Graphics:Images/index_gr_1.gif]](Images/index_gr_1.gif)
![[Graphics:Images/index_gr_2.gif]](Images/index_gr_2.gif)
/. is shortcut notation for ReplaceAll,
and % refers to the last result
Mathematica returned. Using FullSimplify
gives {True, True}, showing that both results
returned satisfy the equation.
![[Graphics:Images/index_gr_3.gif]](Images/index_gr_3.gif)
![[Graphics:Images/index_gr_4.gif]](Images/index_gr_4.gif)
The same method works for the differential equation solver
DSolve and other commands that return rules.
![[Graphics:Images/index_gr_5.gif]](Images/index_gr_5.gif)
![[Graphics:Images/index_gr_6.gif]](Images/index_gr_6.gif)
![[Graphics:Images/index_gr_7.gif]](Images/index_gr_7.gif)
![[Graphics:Images/index_gr_8.gif]](Images/index_gr_8.gif)
You can easily substitute multiple results too.
![[Graphics:Images/index_gr_9.gif]](Images/index_gr_9.gif)
![[Graphics:Images/index_gr_10.gif]](Images/index_gr_10.gif)
![[Graphics:Images/index_gr_11.gif]](Images/index_gr_11.gif)
![[Graphics:Images/index_gr_12.gif]](Images/index_gr_12.gif)
![[Graphics:Images/index_gr_13.gif]](Images/index_gr_13.gif)
For many other operations, you can simply use the inverse command as in
this example.
![[Graphics:Images/index_gr_14.gif]](Images/index_gr_14.gif)
![[Graphics:Images/index_gr_15.gif]](Images/index_gr_15.gif)
![[Graphics:Images/index_gr_16.gif]](Images/index_gr_16.gif)
![[Graphics:Images/index_gr_17.gif]](Images/index_gr_17.gif)
Return to Top
Numerical Tests
Substitute the Result Back into the Original Problem
Let's compare the numerical solution to a differential equation with machine
precision with a numerical solution with a higher-precision setting.
![[Graphics:Images/index_gr_18.gif]](Images/index_gr_18.gif)
![[Graphics:Images/index_gr_19.gif]](Images/index_gr_19.gif)
The following plot shows the logarithm of the difference between the numerical
solution and the differential equation with the default setting of
WorkingPrecision (black) and with
WorkingPrecision set to
22 (red).
![[Graphics:Images/index_gr_20.gif]](Images/index_gr_20.gif)
![[Graphics:Images/index_gr_21.gif]](Images/index_gr_21.gif)
As you can see, the numerical errors are significantly smaller when
using the higher working precision. The rather high first value is an
artifact. The tradeoff for using higher precision is, of course, increased
calculation times.
Return to Top
Random Testing
You can often get a pretty good indication of whether a result is plausible by
plugging in random numbers.
![[Graphics:Images/index_gr_22.gif]](Images/index_gr_22.gif)
![[Graphics:Images/index_gr_23.gif]](Images/index_gr_23.gif)
The following command calculated the difference between the differentiated
result and the original integrand at 20 random points.
![[Graphics:Images/index_gr_24.gif]](Images/index_gr_24.gif)
![[Graphics:Images/index_gr_25.gif]](Images/index_gr_25.gif)
Return to Top
|