Mathematica What technique to integrate this function?

  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Function Integrate
Click For Summary
The discussion centers on the differences in numerical outputs when integrating a function with two slightly different parameters, a=89.9 and a=89+9/10. The user questions the validity of the results from NIntegrate, which yield significantly different values, indicating potential issues with floating-point precision. The sensitivity of the functions to the parameter a is highlighted, suggesting that even minor differences can lead to large discrepancies in integration results. There is a consensus that the large amplitudes of the functions may lead to loss of precision, and the need for rescaling is mentioned. The conversation also touches on the importance of understanding the numerical methods used, with references to Mathematica's WorkingPrecision parameter, which can affect the accuracy of calculations. The user is encouraged to explore variations in the integral and to utilize Mathematica's features to improve precision, similar to methods used in Maple.
member 428835
Hi PF!

Attached are two plots of the same function, one uses a parameter ##a=89.9## and the other uses ##a=89+9/10##. As you can see both functions are very different. Also, using NIntegrate over each gives two different outputs respectively, ##-6.91846*10^{12},-6.91949*10^{19}##.

My question is, how do I know if either is right, and if so which one? I'm obviously leaning towards the non-floating point ##a=89+9/10## as the more correct, but how do I know this integral is even right at all?

Are there other numerical integration strategies I should look at besides NIntegrate?
 

Attachments

  • Float.png
    Float.png
    9.1 KB · Views: 399
  • Non-Float.png
    Non-Float.png
    11.6 KB · Views: 456
Physics news on Phys.org
You could compare the two a values. While they may appear the same, they may instead be subtly different in the lowest bits.

Try a1 - a2 and see if it’s a zero or some small number. Base 10 numbers don’t always map to binary well.
 
jedishrfu said:
You could compare the two a values. While they may appear the same, they may instead be subtly different in the lowest bits.

Try a1 - a2 and see if it’s a zero or some small number. Base 10 numbers don’t always map to binary well.
Mathematica outputs 0. (the decimal after the zero indicates a float.) I tell Mathematica to output more digits and it does not output anything. There has to be some difference though, at least in how the function reads each.
 
Could you give the expressions for the functions which are compared or are they only known explicitly (e.g. a solution to an equation)?
Also, it seems like the functions have very large amplitudes. Perhaps, you should do some re-scaling. Otherwise, you might loose precision.
It looks like the amplitudes of the functions are very sensitive to the parameter ##a##.
 
eys_physics said:
Could you give the expressions for the functions which are compared or are they only known explicitly (e.g. a solution to an equation)?
Also, it seems like the functions have very large amplitudes. Perhaps, you should do some re-scaling. Otherwise, you might loose precision.
It looks like the amplitudes of the functions are very sensitive to the parameter ##a##.
I could give the expressions but they're way too many terms to be meaningful. A bunch of sines and cosines. But there are s TON of them.
Yes, I agree that the functions are very sensitive to ##a##.
 
With such a sensitive integrand and such large numbers it is unlikely that either integral is meaningful.
 
Dale said:
With such a sensitive integrand and such large numbers it is unlikely that either integral is meaningful.
Is there a way to get a good feel for when an integral is not meaningful? See, the integral is a matrix component of an algebraic eigenvalue problem ##K = \lambda M##, which for this case was the ##1,1## component of a ##5\times 5## matrix. It turns out it did not matter whether I used the float or exact number, because I received the same ##\lambda## for each case.

What's happening?
 
Plot lots of variations and see if the results make sense. If they do then it is probably meaningful.
 
joshmccraney said:
I tell Mathematica to output more digits and it does not output anything.

What does this mean? You made Mathematica do all floating point calculations with more (decimal) digits? You did not change the number of digits for calculations, but you displayed more output digits?

I am unfamiliar with Mathematica, but I have used Maple extensively. Maple has a control variable, Digits, that sets the number of digits used in floating point calculations. The default value of Digits is 10. I have found that setting Digits to 20 or 30 can wildly change the value of a sensitive sum in which terms have different signs.
 
  • #10
George Jones said:
What does this mean? You made Mathematica do all floating point calculations with more (decimal) digits? You did not change the number of digits for calculations, but you displayed more output digits?
Yea, I displayed more digits for the 89+9/10 - 89.9, but did not send a command about the amount of digits to be used for floats.

George Jones said:
I am unfamiliar with Mathematica, but I have used Maple extensively. Maple has a control variable, Digits, that sets the number of digits used in floating point calculations. The default value of Digits is 10. I have found that setting Digits to 20 or 30 can wildly change the value of a sensitive sum in which terms have different signs.
Does anyone know how to do this in Mathematica, and what the default is set to?
 
  • #12
eys_physics said:
Yes, Mathematica has a parameter called WorkingPrecision, see https://reference.wolfram.com/language/ref/WorkingPrecision.html. One suggestion to joshmccraney could be to play a bit with that parameter.
Thanks. I'll look into that. Do you know if this is at all similar to setting accuracy goals for numerical integration, say MaxRecursion for example?
 

Similar threads

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