MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Why Doesn't N[Pi,i] Give i Digits For Small i, Math ematica 4,on NT

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20236] RE: [mg20220] Why Doesn't N[Pi,i] Give i Digits For Small i, Math ematica 4,on NT
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Fri, 8 Oct 1999 18:30:14 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

randmarg at magma.ca  wrote:
------------------------
If I execute:

Table[{i, N[Pi, i]}, {i, 1, 20}]

I get:

{{1, 3.14159}, {2, 3.14159}, {3, 3.14159}, {4, 3.14159}, {5, 3.14159},
{6,  3.14159}, {7, 3.14159}, {8, 3.14159}, {9, 3.14159}, {10, 3.14159},
{11, 3.14159}, {12, 3.14159}, {13, 3.14159}, {14, 3.14159}, {15,
3.14159}, {16, 3.14159}, {17, 3.1415926535897932},
{18, 3.14159265358979324}, {19, 3.141592653589793238},
{20, 3.1415926535897932385}}

I'd expect something like
{{1,3},{2,3.1},{3,3.14},{4,3.141},{5,3.1416},{6,3.14159},{7,3.141593},....

It seems N[] only works as expected above 16 digits of requested
precision.

---------------------------

This has been a pet peeve of mine for a long time.  I learned from someone
in this group that SetPrecision will do what for exact numbers.


In[1]:=
Table[{i, SetPrecision[Pi, i]}, {i, 1, 20}]

Out[1]=
{{1,3.},{2,3.1},{3,3.14},{4,3.142},{5,3.1416},{6,3.14159},{7,3.141593},{8,3.
1415927},{9,3.14159265},{10,3.141592654},{11,3.1415926536},{12,3.14159265359
},{13,3.141592653590},{14,3.1415926535898},{15,3.14159265358979},{16,3.14159
2653589793},{17,3.1415926535897932},{18,3.14159265358979324},{19,3.141592653
589793238},{20,3.1415926535897932385}}


However, you can't simply replace any use of N with SetPrecision.
N[expr,100] will only give you 100 digits if (expr) has better than 100
digits of precision.  On the other hand SetPrecision[expr,100] will take any
numeric value and give you a value with 100 digits. With SetPrecision you
don't know which digits are right.  Consider the examples below.


In[2]:=
SetPrecision[3.0/7, 50]

(* Most of the digits are wrong. *)
Out[2]=
0.42857142857142854763807804374664556235074996948242


In[3]:=
N[3.0/7, 50]//InputForm

(* Sorry, all digits farther to the right are unknown. *)
Out[3]=
0.42857142857142855



In[4]:=
N[3/7,50]

(* In this case all 50 digits are correct because 3/7 is exact. *)
Out[4]=
0.42857142857142857142857142857142857142857142857143


--------------------
Regards,
Ted Ersek

For Mathematica tips, tricks see 
http://www.dot.net.au/~elisha/ersek/Tricks.html


  • Prev by Date: Re: Why Doesn't N[Pi,i] Give i Digits For Small i, Mathematica 4,on NT
  • Next by Date: Re: Why Doesn't N[Pi,i] Give i Digits For Small i, Mathematica 4,on NT
  • Previous by thread: Re: Finding lengths of identical sequences in lists
  • Next by thread: Re: Why Doesn't N[Pi,i] Give i Digits For Small i, Mathematica