4

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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Wynne
  • 1,526
  • 9
  • 14
  • 2
    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. – Marius Ladegård Meyer Jun 12 '16 at 08:22
  • 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. – Wjx Jun 12 '16 at 08:39
  • 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 –  Jun 12 '16 at 08:49

1 Answers1

5

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
  • 1
    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}$. – Michael E2 Apr 03 '17 at 10:19