3
$\begingroup$

This is my code

Table[With[{x = 10^n + 1/17}, N[x, {Infinity, 5}]], {n, 0, 5}] // Column

Blockquote

Or like this

SetAccuracy[Table[With[{x = 10^n + 1/17}, N[x]], {n, 0, 5}], 5] // Column

Blockquote

Actually I just want 5-digit accuracy (effective number of digits to the right of the decimal point) and any precision. But the accuracy is 4 and sometimes it is 5.

Update

The documentation has this usage as above

enter image description here

So is it a bug in function of N?

$\endgroup$
5
  • $\begingroup$ the issue is that N takes its accuracy/precision arguments in base 10, but actually constructs a binary result that best captures your specification. Note words like attempts and at most in the documentaiton for N $\endgroup$
    – george2079
    Dec 31, 2015 at 16:36
  • $\begingroup$ I'd say not a bug in N but a rather glaring omission in the docs to give that example and fail to point out that the accuracy does not always guarantee an exact number of decimal digits ultimately get displayed. $\endgroup$
    – george2079
    Dec 31, 2015 at 16:44
  • $\begingroup$ @george2079 Oh,Thinks a lot.Blame I was too careless and I have seen it in Detail . $\endgroup$
    – yode
    Dec 31, 2015 at 17:11
  • $\begingroup$ @george2079 You should really make your comment an answer. $\endgroup$
    – xzczd
    Jan 1, 2016 at 4:40
  • $\begingroup$ Well, actually I think there's a more general issue behind this and many other precision-related question in this site, that is, the rule for precision (not sure I've used the correct terminology) of Mathematica is just similar but not the same as that we used when we calculates with pencil and paper. Maybe we need a community wiki or something for this. $\endgroup$
    – xzczd
    Jan 1, 2016 at 4:56

2 Answers 2

4
$\begingroup$

You are misinterpreting the documentation. A number with no digits to the right of decimal place is considered to have 1 digit of accuracy. Consider

Grid[
  With[{r = Range[0, 4]}, 
    Prepend[
      Table[With[{x = 10^n + 1/17}, N[x, {∞, a}]], {n, r}, {a, r + 1}],
      r + 1]],
  Alignment -> "Decimal",
  Background -> {None, {GrayLevel[0.7], {White}}}, 
  Dividers -> {Black, {2 -> Black}},
  Frame -> True,
  Spacings -> {2, {2, {0.7}}}]

table

Edit

The number of digits seen in the table depends on 1) the setting for number–of-digits-displayed in Preferences and 2) the precision of the numbers being displayed. The accuracy setting does not factor into it.

The numbers that appear to have too many digits simply have higher precision than the others.

$\endgroup$
4
  • $\begingroup$ Sorry for my poor expression.Such as N[Pi^10, {Infinity, 5}] give 4 digit but N[Pi^10, {Infinity, 6}] will give 6 digit after the decimal point,which is confuse me $\endgroup$
    – yode
    Dec 31, 2015 at 16:14
  • 1
    $\begingroup$ As your table,The bottom line of the last two columns has a unexpected number of digits. $\endgroup$
    – yode
    Dec 31, 2015 at 16:19
  • $\begingroup$ I like your answer +1, would be nice to have your comments on Help/Details, Unless numbers in expr are exact, or of sufficiently high precision, N[expr,n] may not be able to give results with n-digit precision. $\endgroup$
    – user9660
    Dec 31, 2015 at 16:47
  • 1
    $\begingroup$ I think this just re-illustrates the question.. $\endgroup$
    – george2079
    Dec 31, 2015 at 16:51
0
$\begingroup$
 Table[N[10^n + 1/17, n + 6], {n, 0, 5}] // Column

enter image description here

Or

 Table[NumberForm[10^n + 1/17., {12, 5}], {n, 0, 5}] // Column

enter image description here

Or

Table[PaddedForm[10^n + 1/17., {12, 5}], {n, 0, 5}] // Column

enter image description here

SetAccuracy only gives the desired result if you combine it with one of the number display functions:

p = 5;
AccountingForm[Column@Table[SetAccuracy[10^n + 1/17, p + 1], {n, 0, 15}], {Infinity,p}]

enter image description here

$\endgroup$
5
  • $\begingroup$ Actually I know there is a workaround to solve this problem.But what a mistake in my usage?If not,do you think a flaw is in function of N? $\endgroup$
    – yode
    Dec 31, 2015 at 13:34
  • $\begingroup$ It's certainly not a flaw with N, but I agree that the behaviour of SetAccuracy is a little bit strange in this case. $\endgroup$
    – eldo
    Dec 31, 2015 at 14:03
  • $\begingroup$ Have you seen the picture I update just now? $\endgroup$
    – yode
    Dec 31, 2015 at 14:06
  • $\begingroup$ Have you seen the first part of my answer? N behaving exactly as you want. The picture you show just clarifies the fact that N[4, {Infinity, 2}] displays one digit after the decimal point and not two. $\endgroup$
    – eldo
    Dec 31, 2015 at 14:26
  • $\begingroup$ N[Pi^10, {Infinity, 5}] give 4 digit but N[Pi^10, {Infinity, 6}] give 6 digit after the decimal point. $\endgroup$
    – yode
    Dec 31, 2015 at 14:58

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.