4
$\begingroup$

Consider the following code:

r = x /. FindRoot[Cos[x] - x == 0, {x, 1}, AccuracyGoal -> 15, 
   PrecisionGoal -> 15, WorkingPrecision -> 100];
Precision[r]

I would expect the Precision of r to be 15 since I'm only asking Mathematica to solve it to 15 digits. But the result is 100, which is the WorkingPrecision I am using. Why?

$\endgroup$
3
  • 2
    $\begingroup$ I think the precision goal is how close you need to get to the true root. Here FindRoot will use 100 digits in x in each step of the iteration towards the root, and when it has found the root to 15 digit precision, it stops, and return that x, which still has a precision of 100. $\endgroup$ Jun 12, 2016 at 8:22
  • $\begingroup$ Just like @Marius said, PrecisionGoal and AccuracyGoal will only inform you the digits you can use. WorkingPrecision will inform you the resulting number's precision, but maybe the latter digits is not usable. $\endgroup$
    – Wjx
    Jun 12, 2016 at 8:39
  • $\begingroup$ See Controlling the Precision of Results and Setting WorkingPrecision->n causes all internal computations to be done to at most n-digit precision. See WorkingPrecision $\endgroup$
    – user9660
    Jun 12, 2016 at 8:49

1 Answer 1

5
$\begingroup$

Here is a short demo. Generate the Dottie number as an exact Root[] object, like so:

dottie = x /. First @ Solve[x == Cos[x] && 0 < x < 1, x];

(Tho you might notice an inexact number in the output, rest assured that the resulting Root[] object is an exact number that can be evaluated to arbitrary precision; the number is there only as a sort of "localization marker".)

Use FindRoot[] to generate an approximation of the Dottie number:

ndottie = x /. FindRoot[Cos[x] - x, {x, 1}, AccuracyGoal -> 5, PrecisionGoal -> 5,
                        WorkingPrecision -> 30];

Altho Precision[ndottie] == 30., the result is not actually accurate to all 30 digits. Here is the relative error:

-Log10[Abs[1 - ndottie/dottie]]
   20.0631570441

which says that the result is accurate to about 20 digits, even with the supposedly low settings. Now, crank up the settings:

ndottie2 = x /. FindRoot[Cos[x] - x, {x, 1}, AccuracyGoal -> 15,
                         PrecisionGoal -> 15, WorkingPrecision -> 30];

and you'll find that ndottie2 - dottie is effectively zero.

$\endgroup$
1
  • 1
    $\begingroup$ One can see with StepMonitor that the relative error estimate in the next-to-last (3rd) step is about $(x_3-x_{2})/x_3=3.8 \times 10^{-5}$, a bit greater than the PrecisionGoal, so FindRoot takes another step. But because of the quadratic convergence in this well-behaved problem, this is closer to the error in $x_2$. The next step has a error estimate of $(x_4-x_3)/x_4=2.3 \times 10^{-10}$, but that means the error in $x_4$ will be close to $10^{-20}$. $\endgroup$
    – Michael E2
    Apr 3, 2017 at 10:19

Your Answer

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

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