Re: A question about N[...]

*To*: mathgroup at smc.vnet.net*Subject*: [mg89421] Re: A question about N[...]*From*: "wyelen at gmail.com" <wyelen at gmail.com>*Date*: Mon, 9 Jun 2008 02:28:09 -0400 (EDT)*References*: <g2fug6$2kg$1@smc.vnet.net>

On 6=D4=C28=C8=D5, =CF=C2=CE=E72=CA=B133=B7=D6, "wye... at gmail.com" <wye...@g= mail.com> wrote: > Recently I came across a puzzling problem which I believed to be > related to the function N. > > My platform is Mathematica 6.0 for Microsoft Windows (32-bit). When > calculating the following > integral, I got different results from Integrate & NIntegrate: > > In[1]:= Integrate[BesselJ[0, 2.405 * r]^2, {r, 0, 20}] > > Out[1]= 0. > > In[2]:= NIntegrate[BesselJ[0, 2.405 * r]^2, {r, 0, 20}] > > Out[2]= 0.864755 > > Guessing a problem caused by numerical number 2.405, I rewrote it as > an exact number: > > In[3]:= Integrate[BesselJ[0, (2 + 405/1000)*r]^2, {r, 0, > 20}] > > Out[3]= 20*HypergeometricPFQ[{1/2, 1/2}, {1, 1, 3/2}, - > (231361/100)] > > then evaluated the numerical value, which was surprisingly still 0.: > > In[4]:= N[%] > > Out[4]= 0. > > but evaluating with 6-digit precision gave the same result as > NIntegrate: > > In[5]:= N[%%,6] > > Out[5]= 0.864755 > > In help page for N it said "N[expr] is equivalent to > N[expr,MachinePrecision]", but evaluating with a > approximate precision didn't gave 0.: > > In[6]:= N[MachinePrecision] > > Out[6]= 15.9546 > > In[7]:= N[%3,15.9546] > > Out[7]= 0.8647551857405188 > > I wonder is this caused by the function N ,or whether I should just > turn to another OS (say Linux) and things will go well. > > Thanks a lot for your reply! Thanks for all your replies:) It seems I have mixed $MachinePrecision-digit precision (where $MachinePrecision = "number of decimal digits of machine-precision"), which is an arbitrary precision algorithm and MachinePrecision = "machine-number precision", which is a machine precision algorithm. This led to a confusion at In[7]. And I haven't realized the precision requirements from the intermediate steps, which may require more than 16 digits. I don't know whether it is a bug or not, but at least I see a way to avoid it :)