0 vs 0.0 in numerical integrand- bug?

In summary, This user's problem is that when they try to evaluate a function at q=0, they get an error message saying that the function is infinite. However, when they evaluate the function at q=0.0001, the function works correctly.
  • #1
muppet
608
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
  • #2
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
 
  • #3
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.
 
  • #4
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.
 
  • #5
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.
 
  • #6
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.
 
  • #7
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?
 
  • #8
Looks like it. Apparently a bug that they found and fixed in version 8.
 
  • #9
Ah well, integrating from 0.0001 it is... thanks for your help.
 

Related to 0 vs 0.0 in numerical integrand- bug?

1. What is the difference between 0 and 0.0 in a numerical integrand?

The main difference between 0 and 0.0 in a numerical integrand is their data type. 0 is an integer while 0.0 is a floating-point number. This means that 0 can only represent whole numbers, while 0.0 can represent fractions or decimals.

2. Why is it important to distinguish between 0 and 0.0 in a numerical integrand?

In a numerical integrand, 0 and 0.0 may have different mathematical interpretations. For example, if 0 represents the absence of a value, then 0.0 may represent a very small value that is still significant in calculations. Distinguishing between the two can prevent errors in calculations and ensure accurate results.

3. Can using 0 instead of 0.0 in a numerical integrand cause a bug?

Yes, using 0 instead of 0.0 in a numerical integrand can potentially cause a bug. This is because, as mentioned earlier, the two have different data types and may be interpreted differently in mathematical operations. It is important to use the appropriate data type for the intended purpose to avoid bugs.

4. How can I avoid encountering issues with 0 vs 0.0 in a numerical integrand?

The best way to avoid issues with 0 vs 0.0 in a numerical integrand is to always be mindful of the data types you are using. Make sure to use 0 for integers and 0.0 for floating-point numbers. Additionally, double-check your calculations and make sure they are using the correct data type for the intended purpose.

5. Are there any specific programming languages that are more prone to bugs with 0 vs 0.0 in a numerical integrand?

There is no specific programming language that is more prone to bugs with 0 vs 0.0 in a numerical integrand. However, some languages may have stricter data type rules and may require more attention to detail when using 0 vs 0.0 in calculations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • Advanced Physics Homework Help
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
2
Views
1K
  • Math Proof Training and Practice
2
Replies
69
Views
4K
  • Set Theory, Logic, Probability, Statistics
Replies
6
Views
2K
  • Sticky
  • Topology and Analysis
Replies
9
Views
5K
Back
Top