Mathematica Decimals give different integrals than fractions; why?

Click For Summary
SUMMARY

The discussion centers on the discrepancies in integral results when using decimal versus fractional representations in Mathematica. It highlights that floating-point numbers cannot always accurately represent certain values, leading to computational errors. For instance, expressions like 3.0*sin(x)*(1.0/3.0) may yield different results than (3.0*sin(x)) / 3.0 due to Mathematica's handling of approximate versus exact numbers. The conversation emphasizes the importance of understanding floating-point arithmetic to avoid such issues.

PREREQUISITES
  • Understanding of floating-point arithmetic and its limitations
  • Familiarity with Mathematica's numerical and symbolic computation methods
  • Knowledge of mathematical functions and their representations in programming
  • Basic programming skills to implement and test code examples
NEXT STEPS
  • Read "What Every Computer Scientist Should Know About Floating-Point Arithmetic"
  • Learn about Mathematica's NIntegrate function and its applications
  • Explore the differences between symbolic and numerical computations in Mathematica
  • Investigate methods for mitigating floating-point errors in numerical analysis
USEFUL FOR

Mathematicians, computer scientists, and software developers who utilize Mathematica for numerical computations and seek to understand the implications of floating-point arithmetic on their results.

member 428835
Just like the title says. Is this due to roundoff?
 
Physics news on Phys.org
You really cannot expect us to be able to help you unless you give a specific example of code.
 
The code is kind of long. Are you sure you want me to give it? There's not a computational difference that you're aware of for exact numbers vs decimals?
 
Can't you illustrate it with a simpler example?

Its well known in computerdom that some numbers can't be represented properly in floating pt format so if Mathematica does a numerical computation with them them then computational error will creep into the calculation.

As an example, if you had some expression like ##3.0*sin(x)*(1.0/3.0)## and Mathematica symbolically reduces it to sin(x) then that result might be different from ##(3.0*sin(x)) / 3.0## where Mathematica didn't see the ONES identity and did the numerical computations of 3.0 * sin(x) then dividing by 3.0.

For larger numbers the result difference might be more pronounced as floating pt numbers kep to a certain limited digit precision.

 
jedishrfu said:
Can't you illustrate it with a simpler example?

Its well known in computerdom that some numbers can't be represented properly in floating pt format so if Mathematica does a numerical computation with them them then computational error will creep into the calculation.

As an example, if you had some expression like ##3.0*sin(x)*(1.0/3.0)## and Mathematica symbolically reduces it to sin(x) then that result might be different from ##(3.0*sin(x)) / 3.0## where Mathematica didn't see the ONES identity and did the numerical computations of 3.0 * sin(x) then dividing by 3.0.

For larger numbers the result difference might be more pronounced as floating pt numbers kep to a certain limited digit precision.


I'm not sure how to illustrate it with a simpler example, which shows how little I know about the issue. I can say when I plot a function (takes a lot of code to construct) one plot has max of 50 and the other has max 6000. Do you want me to post the code or pictures so you can see?
 
Mathematica does treat approximate and exact numbers differently. Usually approximate numbers make Mathematica evaluate it numerically using NIntegrate. In contrast an integrand with exact numbers will be solved analytically and then the limits of integration will be substituted at the end.
 
If you are going to rely on programming/software then you should really consider reading this article, it has been cited a huge number of times because of its importance:
What Every Computer Scientist Should Know About Floating-Point Arithmetic
https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf

I think that Dale is trying to tell you something about your understanding of what Mathematica does behind the scenes. Consider it seriously.
 

Similar threads

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