4
$\begingroup$

At the moment I am considering a "difficult", highly-oscillatory integral in Mathematica. It calculates the integral without any complaints. However, I am also trying out a numerical method with which I am calculating the same integral. The relative difference between the two results is of $\mathcal{O}(10^{-3})$. It appears that this difference stays the same if I reduce the stepsize of my numerical method. This is strange, as the difference should become smaller (provided my method is correct, of course).

Hence my question:

If Mathematica does not give any errors when evaluating an expression, can we be absolutely certain that its answer is reliable up to a decent precision (say, $\mathcal{O}(10^{-10})$?

And a related question:

Is there a way to let Mathematica print the precision with which it has obtained a certain answer?

$\endgroup$
3
  • $\begingroup$ You'd better add a concrete example. BTW, have you tried the WorkingPrecision option? $\endgroup$
    – xzczd
    Feb 9 '15 at 9:23
  • $\begingroup$ As to your second question, have you looked at Precision? $\endgroup$
    – m_goldberg
    Feb 9 '15 at 13:07
  • $\begingroup$ tutorial/NIntegrateOverview contains lots of information. The pages on the integration rules discussed how the error is estimated. There is an example that shows how it can get fooled. $\endgroup$
    – Michael E2
    Feb 9 '15 at 14:20
5
$\begingroup$

I would say that the answer to the first question is, no, if Mathematica does not give any errors when evaluating an expression, then we cannot be absolutely certain that its answer is reliable up to a decent precision. This is shown in the section Examples of Pathological Behavior in the tutorial NIntegrate Integration Rules.

Given that the previous answer is no, there is no way for Mathematica to print the precision with which it has obtained a certain answer.

If NIntegrate returns a value with no error or warning messages, I think it is safe to assume that the algorithm's error estimate meets the criterion set by PrecisionGoal and AccuracyGoal. But as the tutorial shows, that is not a guarantee that it has actually been met.

$\endgroup$
1
  • $\begingroup$ One possibility is to try, if applicable, various applicable methods and compare their results against the method you are developing yourself. This can be done with a "toy" version of the integral being evaluated (hopefully with a known closed form!) as well as the actual integral itself. For the truly paranoid, one can also check against NDSolve[] which often has to be more careful than NIntegrate[]. $\endgroup$
    – J. M.'s torpor
    May 27 '15 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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