MathGroup Archive 2006

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

Search the Archive

Re: Displaying decimals

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63486] Re: Displaying decimals
  • From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 3 Jan 2006 01:24:38 -0500 (EST)
  • Organization: The Open University, Milton Keynes, U.K.
  • References: <dpb0q8$1ph$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Lea Rebanks" <lrebanks at netvigator.com> a écrit dans le message de news: 
dpb0q8$1ph$1 at smc.vnet.net...
|
| Given the enclosed function, I can not make Mathematica v5.1 display
| greater than 3 decimals. Please help.
|
| slope[x_]:=160.245051009838+0.05888359189242*x
|
| EG. slope[50] = 163.189
|
| I don't know how or why this is happening.  I have tried N[expr,20] to
| no avail.
|
| Many thanks for your attention.
|
| Lea Rebanks.
|

Hi Lea,

As it is coded, the function slope does and returns its computation in 
machine precision (limited precision, hardware dependent, evaluate 
$MachinePrecision to see it).

On the other hand, the built-in function *N* expects numbers expressed in 
arbitrary precision to be able to display them with the required number of 
significant digits. To see the difference compare your function slope 
against the function slope2 below.

In[1]:=
slope[x_]:=160.245051009838+0.05888359189242*x

In[2]:=
res=slope[50]

Out[2]=
163.189

In[3]:=
Precision[res]

Out[3]=
MachinePrecision

You can see the number with all of its digits in *InputForm*

In[4]:=
InputForm@res

Out[4]//InputForm=
163.189230604459

Note that the precision of the coefficients are expressed by adding `15 at 
the end of each number

In[5]:=
slope2[x_]:=160.245051009838`15+0.05888359189242`15*x

In[6]:=
res2=slope2[50]

Out[6]=
163.189230604459

In[7]:=
Precision[res2]

Out[7]=
15.

In[8]:=

N[res2,10]

Out[8]=
163.1892306

Happy New Year!
/J.M.

(************** Content-type: application/mathematica **************
                     CreatedBy='Mathematica 5.2'

                    Mathematica-Compatible Notebook

This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do
one of the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the
  application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.

For more information on notebooks and Mathematica-compatible
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info at wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from
Wolfram Research.
*******************************************************************)

(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      2763,        111]*)
(*NotebookOutlinePosition[      3408,        133]*)
(*  CellTagsIndexPosition[      3364,        129]*)
(*WindowFrame->Normal*)


Notebook[{
Cell[BoxData[
    \(slope[x_] := 160.245051009838 + 0.05888359189242*x\)], "Input"],

Cell[CellGroupData[{

Cell[BoxData[
    \(res = slope[50]\)], "Input"],

Cell[BoxData[
    \(163.189230604459`\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
    \(Precision[res]\)], "Input"],

Cell[BoxData[
    \(MachinePrecision\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
    \(InputForm@res\)], "Input"],

Cell["163.189230604459", "Output"]
}, Open  ]],

Cell[BoxData[
    \(slope2[x_] :=
      160.245051009838`15 + 0.05888359189242`15*x\)], "Input"],

Cell[CellGroupData[{

Cell[BoxData[
    \(res2 = slope2[50]\)], "Input"],

Cell[BoxData[
    \(163.1892306044589999999999999998`15. \)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
    \(Precision[res2]\)], "Input"],

Cell[BoxData[
    \(15.`\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
    \(N[res2, 10]\)], "Input"],

Cell[BoxData[
    \(163.189230604459`10. \)], "Output"]
}, Open  ]]
},
FrontEndVersion->"5.2 for Microsoft Windows",
ScreenRectangle->{{0, 1280}, {0, 717}},
WindowSize->{495, 593},
WindowMargins->{{24, Automatic}, {Automatic, 30}}
]

(*******************************************************************
End of Mathematica Notebook file.
*******************************************************************)



  • Prev by Date: Re: Unknown Sum of Series
  • Next by Date: Re: Can anybody help?
  • Previous by thread: Re: Displaying decimals
  • Next by thread: Re: Displaying decimals