Decimals give different integrals than fractions; why?

In summary, the conversation discusses the issue of roundoff and computational differences between exact numbers and decimals in Mathematica. The speaker explains that Mathematica treats approximate and exact numbers differently, with approximate numbers being evaluated numerically and exact numbers being solved analytically. The conversation also mentions the potential for computational errors to occur when working with floating point numbers, and suggests reading an article about floating point arithmetic for a better understanding.
  • #1
member 428835
Just like the title says. Is this due to roundoff?
 
Physics news on Phys.org
  • #2
You really cannot expect us to be able to help you unless you give a specific example of code.
 
  • #3
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?
 
  • #4
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.

 
  • #5
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?
 
  • #6
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.
 
  • #7
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.
 

1. Why do decimals give different integrals than fractions?

Decimals and fractions represent numbers differently. Decimals have a fixed number of decimal places, while fractions have a numerator and denominator. This difference in representation leads to different integrals because the integration process involves manipulating the variable in the equation, and decimals and fractions are treated differently in this process.

2. How does the integration process differ for decimals and fractions?

Integrating a fraction involves finding the antiderivative of the function, while integrating a decimal involves converting it to a fraction and then finding the antiderivative. This extra step in converting decimals to fractions can result in different integrals.

3. Can decimals and fractions ever give the same integral?

Yes, there are cases where decimals and fractions can give the same integral. This typically occurs when the decimal can be simplified to a fraction or when the decimal is a repeating decimal that can be expressed as a fraction.

4. Are there any advantages to using decimals over fractions in integration?

Using decimals can sometimes make integration easier and more efficient, as decimals can often be converted to fractions with simple calculations. Additionally, decimals can provide more precise results compared to fractions, which can be important in certain scientific applications.

5. Are there any situations where using fractions is preferable for integration?

Yes, there are situations where using fractions may be more beneficial for integration. For example, when dealing with irrational numbers or functions with complex denominators, it may be easier to work with fractions rather than decimals. Additionally, some integration techniques, such as partial fractions, work better with fractions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Replies
4
Views
1K
  • Calculus and Beyond Homework Help
Replies
8
Views
897
  • High Energy, Nuclear, Particle Physics
Replies
1
Views
464
  • Precalculus Mathematics Homework Help
Replies
9
Views
570
  • Calculus and Beyond Homework Help
Replies
16
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Replies
32
Views
3K
  • Introductory Physics Homework Help
Replies
8
Views
2K
Replies
2
Views
1K
Back
Top