0 vs 0.0 in numerical integrand- bug?

  • Thread starter Thread starter muppet
  • Start date Start date
  • Tags Tags
    Bug Numerical
Click For Summary
The discussion revolves around a numerical integration issue in Mathematica, specifically related to the evaluation of a function at q=0 versus q=0.0. Users report encountering errors such as "Infinite expression 1/0" and "Indeterminate expression ComplexInfinity" when using a decimal representation of zero, while the exact zero yields valid results. The problem appears to stem from how Mathematica handles precision and representation of numbers, with some users suggesting it may be a bug fixed in later versions. The conversation highlights the complexities of numerical accuracy and precision in Mathematica, emphasizing the need for careful handling of zero values in calculations. The issue ultimately leads to a workaround of integrating from a small positive value instead of zero.
muppet
Messages
602
Reaction score
1
Hi All,

A slight problem I've had with a function defined by a numerical integral. The definition is
f[q_,c_,n_]:=NIntegrate[\[Beta]*BesselJ[0,q*\[Beta]]*(E^(I*c*((\[Beta] BesselK[1,\[Beta]] HypergeometricPFQ[{1},{1+n/2,1+n/2},\[Beta]^2/4]+n BesselK[0,\[Beta]] HypergeometricPFQ[{1},{1+n/2,n/2},\[Beta]^2/4])/n^2))-1),{\[Beta],0,Infinity},Method->"ExtrapolatingOscillatory"]

I can evaluate this at q=0 without problems. But I've been filling out tables of values with the intent of constructing interpolating functions, and getting this error message:
Power::infy: Infinite expression 1/0. encountered. >>
\[Infinity]::indet:Indeterminate expression ComplexInfinity encountered.
NIntegrate::nlim: \beta=Indeterminate is not a valid limit of integration.

Looking at the results this seems to be occurring when q vanishes; I'm getting results like

NIntegrate[\[Beta]*BesselJ[0, 0.*\[Beta]]*(E^(I*7.976042329074821*((\[Beta]*BesselK[1, \[Beta]]*HypergeometricPFQ[{1}, {1 + 3/2, 1 + 3/2}, \[Beta]^2/4] + 3*BesselK[0, \[Beta]]*HypergeometricPFQ[{1}, {1 + 3/2, 3/2}, \[Beta]^2/4])/3^2)) - 1), {\[Beta], 0, Infinity}, Method -> "ExtrapolatingOscillatory"]

Sure enough, evaluating f[0.00,18,4] reproduces these messages, wheras f[0,18,4] gives me a nice answer. Can someone explain to me what's going on here? Is this actually a bug or am I missing something about how Mathematica is handling the decimals?

Thanks in advance.
 
Physics news on Phys.org
Don't know anything about Mathematica...just a quick awareness note...are you aware of integral division? does mathematica use it?

3.0/2 = 1.5
3/2.0 = 1.5

3/2 = 1

3.0/4 = 0.75
3/4.0 = 0.75
3/4 = 0

just checking
 
Thanks for your reply- I am aware of it, and Mathematica doesn't as far as I'm aware use it- it gives 3/2 as a fraction by default.
 
In Mathematica
0. or 0.0 or 0.000 or 0.0000 will all be displayed as 0. and are approximately zero with MachinePrecision of about 15.9546 digits and Accuracy of about 307.653. Read the help on this.
With more digits after the decimal point or with other tricks I think I remember you can force even zero to have additional precision, but Precision[0.000000000000000000000000000000000000000000000000] still says it is MachinePrecision.

1/0. is approximately infinity but displays as ComplexInfinity.
1/0 is exactly ComplexInfinity, I think.
ComplexInfinity and DirectedInfinity and Indeterminate are all documented in the help pages.

Accuracy and precision are at least as big a tar pit in Mathematica as they are in numerical analysis, and probably bigger.
 
Thanks for your reply. I don't see how I'm dividing by zero anywhere! I have absolutely no idea why mathematica is generating that message. I have even less of a clue why the problem arises if my 0 is a machine precision number, but not if it's exactly zero.
 
muppet said:
Hi All,

A slight problem I've had with a function defined by a numerical integral. The definition is
f[q_,c_,n_]:=NIntegrate[\[Beta]*BesselJ[0,q*\[Beta]]*(E^(I*c*((\[Beta] BesselK[1,\[Beta]] HypergeometricPFQ[{1},{1+n/2,1+n/2},\[Beta]^2/4]+n BesselK[0,\[Beta]] HypergeometricPFQ[{1},{1+n/2,n/2},\[Beta]^2/4])/n^2))-1),{\[Beta],0,Infinity},Method->"ExtrapolatingOscillatory"]

I can evaluate this at q=0 without problems. But I've been filling out tables of values with the intent of constructing interpolating functions, and getting this error message:
Power::infy: Infinite expression 1/0. encountered. >>
\[Infinity]::indet:Indeterminate expression ComplexInfinity encountered.
NIntegrate::nlim: \beta=Indeterminate is not a valid limit of integration.

Looking at the results this seems to be occurring when q vanishes; I'm getting results like

NIntegrate[\[Beta]*BesselJ[0, 0.*\[Beta]]*(E^(I*7.976042329074821*((\[Beta]*BesselK[1, \[Beta]]*HypergeometricPFQ[{1}, {1 + 3/2, 1 + 3/2}, \[Beta]^2/4] + 3*BesselK[0, \[Beta]]*HypergeometricPFQ[{1}, {1 + 3/2, 3/2}, \[Beta]^2/4])/3^2)) - 1), {\[Beta], 0, Infinity}, Method -> "ExtrapolatingOscillatory"]

Sure enough, evaluating f[0.00,18,4] reproduces these messages, wheras f[0,18,4] gives me a nice answer. Can someone explain to me what's going on here? Is this actually a bug or am I missing something about how Mathematica is handling the decimals?

Thanks in advance.
Which version of Mathematica are you using? I evaluated f[0,18,4] and f[0.00,18,4] and got -2.85044 + 5.52726 I each time with no error messages in either case. I use 8.0.1.0 on 32-bit Windows.
 
Thanks DaleSpam. I'm using mathematica 7.0.1.0 on Ubuntu 12.04. That's the result I got for f[0,18,4] . Bug?
 
Looks like it. Apparently a bug that they found and fixed in version 8.
 
Ah well, integrating from 0.0001 it is... thanks for your help.
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 19 ·
Replies
19
Views
4K