43
$\begingroup$

I'm trying to understand exactly what WorkingPrecision, AccuracyGoal and PrecisionGoal mean for the result of NDSolve.

I presume WorkingPrecision simply means the number of decimal places used internally by Mathematica at various points throughout the calculation on its scratchpad, and therefore essentially gives upper limit to what the accuracy/precision of final result can be.

Now I understand Accuracy/Precision somewhat in the lab sense (Accuracy is how close you are to the true value, Precision is how repeatable the value you get is in some sense; or to use the dartboard analogy-if you're near the bullseye that's accurate-if you hit the the outskirts in the same place 100 times that's precise but not accurate), but not sure I know how these correlate to the Mathematica concepts...

If I set AccuracyGoal->3, PrecisionGoal->4 in NDSolve, what does that say about the function I get spat out? It looks like the definition on the help pages is that AccuracyGoal of 3 would mean 3 significant figures are correct, whereas PrecisionGoal of 4 would give 4 digits after the decimal are correct... e.g if the answer spat out is $89.7895$. What does it mean though in this case to say 3 significant figs are correct, but 4 digits after decimal place are also correct? Seems inconsistent (just a rule of thumb?).

The help pages also state:

With AccuracyGoal->a and PrecisionGoal->p, Mathematica attempts to make the numerical error in a result of size be less than $10^{-a}+|x|10^{-p}$

Does this mean if I did have AccuracyGoal->3, PrecisionGoal->4 and NDSolve spat out $89.7895$ the numerical error would be $10^{-3}+89.7895\cdot 10^{-4}=0.0997895$ ? so my answer is really $89.7895\pm 0.0997895$ ? or is there a different definition of numerical error here?

Thanks for any clarifications.

$\endgroup$
2
  • $\begingroup$ there is an answer here that is related (but does not answer your particular question) $\endgroup$
    – acl
    Commented Aug 6, 2012 at 17:00
  • $\begingroup$ This is a very nice question! $\endgroup$
    – Leo Fang
    Commented Jul 22, 2013 at 14:08

2 Answers 2

9
$\begingroup$

Regarding your last question: in the docs for FindRoot it says that

FindRoot continues until either of the goals specified by AccuracyGoal or PrecisionGoal is achieved.

The same thing is mentioned in the docs for NMinimize.

On the other hand, the docs for NDSolve say

AccuracyGoal effectively specifies the absolute local error allowed at each step in finding a solution, while PrecisionGoal specifies the relative local error.

and also

NDSolve adapts its step size so that the estimated error in the solution is just within the tolerances specified by PrecisionGoal and AccuracyGoal.

So we are reduced to trying to work out whether "and" really means "and" in which case it'll try to satisfy both, or if it behaves like FindRoot.

(this is more of a comment than an answer, but it's too long)

$\endgroup$
3
  • 1
    $\begingroup$ I'll erase this in an hour or so when I know that you have seen it (as I said it's an overlong comment) $\endgroup$
    – acl
    Commented Aug 6, 2012 at 17:30
  • 3
    $\begingroup$ Don't delete it! I found it very educational, even if it does not answer the question explicitly. $\endgroup$
    – Thomas
    Commented Aug 7, 2012 at 10:37
  • 1
    $\begingroup$ Yes this is nice to know, thanks, but still wondering about a lot of things, if anyone out there can say more. $\endgroup$
    – fpghost
    Commented Aug 8, 2012 at 11:08
2
$\begingroup$

In addition the difference between NDSolve and other solvers that @acl cites, the following about whether "and" in the quoted passage means "and":

NDSolve adapts its step size so that the estimated error in the solution is just within the tolerances specified by PrecisionGoal and AccuracyGoal.

Here, the "estimated error" refers to local error at the step, not to an estimate of accumulated error. I refer to Norms in NDSolve:

NDSolve uses norms of error estimates to determine when solutions satisfy error tolerances. In nearly all cases the norm has been weighted, or scaled, such that it is less than 1 if error tolerances have been satisfied and greater than 1 if error tolerances are not satisfied.

The norm may be specified by NormFunction. The standard one used is NDSolve`ScaledVectorNorm, which is documented at the end of the norms tutorial. Its usage has the following form. Let prec and acc be the PrecisionGoal and AccuracyGoal respectively. Let sol and err be the solution vector and truncation error estimate (actual, not relative). Finally, let p be the exponent of the norm (1 <= p <= Infinity, as in the $L^p$ norm). Then the typical usage is the following:

ScaledVectorNorm[p, {10^-prec, 10^-acc}][err, sol]

And the form

$$\left(\frac{1}{n} \sum _{j=1}^n \left(\frac{\left| \text{err}_j\right| }{10^{-\text{acc}}+10^{-\text{prec}} \left| \text{sol}_j\right| }\right){}^p\right){}^{{1}/{p}}\tag{1}$$

The scaled norm used in an NDSolve problem may be obtained like this (from the tutorial):

state = First[
  NDSolve`ProcessEquations[{x''[t] + x[t] == 0,
    x[0] == 1, x'[0] == 0}, x, t]];
(*...*)
svn = state["Norm"]
(* Out[]= NDSolve`ScaledVectorNorm[2, {1.05367*10^-8, 
  1.05367*10^-8}, NDSolve`ProcessEquations]*)

Now, what about "and"? It's closer to an "or", a "fuzzy or", if you will. As noted in my answer to Is manual adjustment of AccuracyGoal and PrecisionGoal useless?, when

When $10^{-\text{prec}}\,\|\text{sol}\| <\mskip-4mu< 10^{-\text{acc}}$, the approximation $$10^{-\text{acc}} + 10^{-\text{prec}}\,\|\text{sol}\| \approx 10^{-\text{acc}}$$ implies that if the error indicates that $\text{sol}$ is correct to at least $\text{acc}$ digits past the decimal point, the error is acceptable. And when $10^{-\text{acc}} <\mskip-4mu< 10^{-\text{prec}}\,\|\text{sol}\|$, the approximation $$10^{-\text{acc}} + 10^{-\text{prec}}\,\|\text{sol}\| \approx 10^{-\text{prec}}\,\|\text{sol}\|$$ implies that if the error indicates that $\text{sol}$ is correct to at least the leading $\text{prec}$ digits, the error is acceptable. When $10^{-\text{prec}}\,\|\text{sol}\|$ is approximately equal to $10^{-\text{acc}}$, there is a fuzzy transition, with the acceptable error being $2\times10^{-\text{acc}}$ when they are dead equal. Thus depending on how $\|\text{sol}\|$ varies, the error criterion can be dominated by precision or accuracy. Ignoring the transistion, one could roughly simplify the criterion as $$\|\text{err}\| \lessapprox \mathop{\text{max}}\left(10^{-\text{prec}}\,\|\text{sol}\|,10^{-\text{acc}}\right) \,.$$

Finally a caveat: The error estimations are usually theoretical bounds on the error. They are based on (1) assumptions about the differential equation and its solution and (2) discrete sampling. Thus in various ways the error may be mis-estimated in edge-cases.


In sum, the OP seems to have accurately grasped WorkingPrecision. In my mind, I think of it as a way to manage the effect of round-off errors. In a numerically unstable problem, raising it may be the best way to solve the problem. I think of AccuracyGoal as defining how big zero is: that is, errors less than it can be accepted as equivalent to zero error. It also mean that it is acceptable for solutions less than it in magnitude to bounce between positive and negative values. I think of PrecisionGoal as the precision goal for solutions when they are larger than the magnitude implied by AccuracyGoal.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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