0 vs 0.0 in numerical integrand- bug?

  • Thread starter Thread starter muppet
  • Start date Start date
  • Tags Tags
    Bug Numerical
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
8 replies · 3K views
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?
 
Ah well, integrating from 0.0001 it is... thanks for your help.