What technique to integrate this function?

I have no idea what Mathematica's default precision is, but the tutorial says"For machine‐precision numbers, the precision is typically determined by the computer system you are using."If you really care about the precision of your calculations, I suggest you read that tutorial.In summary, there is a discrepancy between the two functions with different values for the parameter ##a##, causing two different outputs for the integral. It is suggested to compare the values of ##a## and use a higher working precision to ensure accuracy in the calculations. It is also recommended to plot different variations of the functions to better understand the sensitivity of the integrand. Additionally, it is mentioned that changing the number of digits used in floating point calculations can greatly affect the results
  • #1
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: 356
  • Non-Float.png
    Non-Float.png
    11.6 KB · Views: 403
Physics news on Phys.org
  • #2
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.
 
  • #3
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.
 
  • #4
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##.
 
  • #5
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##.
 
  • #6
With such a sensitive integrand and such large numbers it is unlikely that either integral is meaningful.
 
  • #7
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?
 
  • #8
Plot lots of variations and see if the results make sense. If they do then it is probably meaningful.
 
  • #9
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?
 
  • #13

FAQ: What technique to integrate this function?

What is the best technique to integrate a function?

The best technique to integrate a function depends on the specific function and the desired level of accuracy. Some common techniques include the trapezoidal rule, Simpson's rule, and the midpoint rule. It is important to consider the complexity and smoothness of the function when choosing a technique.

How do I know which integration technique is appropriate for my function?

To determine which integration technique is appropriate for your function, you can start by considering the properties of the function such as continuity, differentiability, and smoothness. You can also consult with a mathematics expert or refer to numerical integration tables for guidance.

Can I use any integration technique for any function?

No, not all integration techniques can be used for all functions. Some techniques may be more suitable for certain types of functions, such as periodic functions or functions with discontinuities. It is important to carefully consider the properties of your function before selecting an integration technique.

What is the difference between numerical and analytical integration techniques?

Numerical integration techniques use numerical methods to approximate the value of an integral, while analytical integration techniques use mathematical formulas to find the exact value of an integral. Numerical techniques are typically used when an exact solution is not possible or is too complex to compute.

How can I improve the accuracy of my integrated function?

There are several ways to improve the accuracy of an integrated function. One method is to decrease the step size or increase the number of intervals used in the integration process. Another method is to use more advanced integration techniques that can handle complex functions or have higher levels of accuracy. Additionally, verifying the results with multiple integration techniques can help ensure accuracy.

Similar threads

Replies
13
Views
2K
Replies
1
Views
1K
Replies
1
Views
4K
Replies
1
Views
1K
2
Replies
58
Views
6K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
5
Views
3K
Back
Top