Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

RE: Wrong Precision with "N" ??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24140] RE: [mg24108] Wrong Precision with "N" ??
  • From: "David Park" <djmp at earthlink.net>
  • Date: Wed, 28 Jun 2000 02:11:55 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

J.R.,

The documentation is a little misleading on the purpose of N, and its
behavior has changed with later versions of Mathematica.

The purpose of N is to change an exact number to an approximate number. If
the precision asked for is equal to or less than the machine precision, then
it produces a machine precision number as in your examples. If the precision
specified is greater than the machine precision, then it produces an
extended precision approximate number.

Machine precision numbers in Version 4 are always displayed with 6 places,
but dropping trailing zeros. This can be changed with the Option Inspector.
Using N with the precision less than 6 will not change this.

N should not be used to format numbers for output. If you want to do that,
use NumberForm, or ScientificForm, EngineeringForm etc.

If you wish to change the precision of a number, use SetPrecision. This
topic is discussed at greater length in Sections 3.1.4 through 3.1.6 in the
Mathematica Book. The following creates a new number with a precision of 3,
and I believe that it will not be used as a machine precision number.

shortpi = SetPrecision[Pi, 3]
3.14

Precision[shortpi]
3

If all you wish to do is format output, do this...

NumberForm[N[Pi], 3]
3.14

Note that the precision of N[Pi,n] is machine precision unless n is greater
than machine precision.

Table[Precision[N[Pi, n]], {n, 5, 20}]
{16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 18, 19, 20}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

> -----Original Message-----
> From: J.R. Chaffer [mailto:jrchaff at mcn.net]
To: mathgroup at smc.vnet.net

> Will someone explain to this newbie why the advertised
> behavior of the numerical evaluation function "N" to some
> specific precision - flatly ignores the second argument?
>
> For example, on my machine,
>
> N[Pi,2] = N[Pi,3] = N[Pi,4] = N[Pi,10] = 3.14159
>
> which is not at all what 'Help', and any number of books,
> claim, with no explanation of why it just might not work
> out that way (??)
>
> Thanks,
> J.R. Chaffer
>



  • Prev by Date: defining myIntegrate
  • Next by Date: Re: Wrong Precision with "N" ??
  • Previous by thread: Wrong Precision with "N" ??
  • Next by thread: Re: Wrong Precision with "N" ??