MathGroup Archive 2006

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

Search the Archive

Re: Mathematica bugs?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67319] Re: [mg67301] Mathematica bugs?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 18 Jun 2006 05:13:08 -0400 (EDT)
  • References: <200606170836.EAA27990@smc.vnet.net> <37A0E477-F2A6-4B4D-9F8C-F2A0237EE906@mimuw.edu.pl>
  • Sender: owner-wri-mathgroup at wolfram.com

On 17 Jun 2006, at 20:25, Andrzej Kozlowski wrote:

>
> On 17 Jun 2006, at 17:36, Yaroslav Bulatov wrote:
>
>> When I run the following line
>> x = Pi/4; For[i = 0, i < 56, i += 1, x = 2*Abs[x - 1/2]]; N[x]
>> I get
>> 3.
>>
>> But x should always stay between 0 and 1, why do I get 3?
>>
>> Also
>> x = Pi/4; For[i = 0, i < 50, i += 1, x = 2*Abs[x - 1/2]]; N[Log[x]]
>> gives me
>> Indeterminate
>>
>> How can I get an indeterminate here?
>>
>
>
> Simply a very usual example of loss of precision due to your using  
> machine precision arithmetic.
>
> In[4]:=
> x = Pi/4; For[i = 0, i < 56, i += 1, x = 2*Abs[x - 1/2]]; N[x,20]
>
> Out[4]=
> 0.79387245267980382900
>
> In[5]:=
> Pi/4; For[i = 0, i < 50, i += 1, x = 2*Abs[x - 1/2]]; N[Log[x],20]
>
> Out[5]=
> -0.82266639946997263758
>
> No bugs at all.
>
> Andrzej Kozlowski


Actually, at least with Mathematica 5 or later, there is no need to  
request 20 digits of precision: even 2 digits will work fine:


x = Pi/4; For[i = 0, i < 56, i += 1, x = 2*Abs[x - 1/2]]; N[x,2]


0.79


Pi/4; For[i = 0, i < 50, i += 1, x = 2*Abs[x - 1/2]]; N[Log[x],2]


-0.82

When you use N alone it is an entirely different matter the  
computation is done with "machine precision" (in other words, not  
control over precision whatever)  so in the case of this kind  
iteration the answer that you get can be virtually anything.

Andrzej Kozlowski
Tokyo, Japan




  • Prev by Date: Re: Mathematica bugs?
  • Next by Date: Re: Package writing
  • Previous by thread: Re: Mathematica bugs?
  • Next by thread: Re: Mathematica bugs?