0 vs 0.0 in numerical integrand- bug?

  • Thread starter Thread starter muppet
  • Start date Start date
  • Tags Tags
    Bug Numerical
Click For Summary

Discussion Overview

The discussion revolves around an issue encountered with a numerical integral function in Mathematica, specifically related to the evaluation of the function at zero versus a small decimal value. Participants explore the implications of using different representations of zero in the context of numerical integration.

Discussion Character

  • Technical explanation, Debate/contested

Main Points Raised

  • One participant describes a function defined by a numerical integral that fails to evaluate correctly when using a decimal representation of zero (0.00) compared to an exact integer zero (0).
  • Another participant raises a question about integral division in Mathematica, suggesting that the software might handle decimal and integer divisions differently.
  • A participant clarifies that Mathematica does not use integral division and defaults to fractions for integer division.
  • Discussion includes details about how Mathematica displays and handles precision and accuracy, noting that different representations of zero may lead to different computational behaviors.
  • One participant expresses confusion about why an error occurs with a machine precision number while it does not with an exact zero.
  • A later reply indicates that a participant using a different version of Mathematica does not encounter the same issue, suggesting a potential bug in the version being discussed.
  • Another participant concludes that the issue may be a bug that was fixed in a later version of Mathematica.
  • One participant suggests a workaround by integrating from a small positive value instead of zero.

Areas of Agreement / Disagreement

Participants do not reach a consensus on whether the issue is a bug or a result of how Mathematica handles numerical precision. There are competing views regarding the behavior of the software and its treatment of zero.

Contextual Notes

Limitations include the dependence on specific versions of Mathematica, as different versions may exhibit different behaviors regarding numerical integration and precision handling.

muppet
Messages
602
Reaction score
0
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
3K
  • · 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 69 ·
3
Replies
69
Views
9K
  • · Replies 5 ·
Replies
5
Views
3K