Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.6K Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Explain behavior of N function displayed precision?

Posted 8 years ago
POSTED BY: Albert Cattani
4 Replies
Posted 8 years ago

excellent explnation. Thank you. I am starting to understand Mathematica at a more subtle level.

POSTED BY: Albert Cattani

Albert,

To enter any number to a specific precision you can use a shortcut: entering 0.5`30 will give you 0.5 with 30 digits of precision. The prime is the character above the Tab key.

Unless you specifically specify the precision, as soon as you enter a decimal point you are using machine precision. That is why using 1/2 instead of 0.5 will maintain the expression with infinite precision until you either use N[] to truncate it or mix it with some real numbers with decimal points.

Regards,

Neil

POSTED BY: Neil Singer
Posted 8 years ago

wow !! ... Thank you .... so it's the default behavior of Machine Precision vs setting a precision. Based on your answer I changed .5 to .50000000000000000000 and got the same result you did with SetPrecission

Are there best practice guidelines on how to introduce precision. Using .5 vs 1/2 while arithmetically correct may not give me the result I expect.

It seems that I should enter the accuracy I want (.50000000000000000000) or enter a calculation (1/2) allowing Mathematica to use its internal precision

POSTED BY: Albert Cattani

It's not a unexplained behavior it is a normal behavior (not a bug).

phi1 = (1 + Sqrt[5])/2; N[phi1, 20] 
phi2 = (1 + 5^(1/2))/2; N[phi2, 20] 
phi3 = (1 + 5^(SetPrecision[0.5, 20]))/2; N[phi3, 20] 

(* 1.6180339887498948482 *)
(* 1.6180339887498948482 *)
(* 1.6180339887498948482 *)

because:

{Precision[(1 + 5^(.5))/2], Precision[(1 + 5^(1/2))/2]}

(* {MachinePrecision, \[Infinity]} *)

This is very well explained in this book

POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard