How Do You Numerically Evaluate Infinite Integrals in C++?

  • Context: Undergrad 
  • Thread starter Thread starter daviddoria
  • Start date Start date
  • Tags Tags
    Infinite Integrals
Click For Summary

Discussion Overview

The discussion revolves around the challenges of numerically evaluating infinite integrals in C++. Participants express concerns about the limitations of numerical integration functions when faced with infinite limits and explore various strategies for addressing these issues.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant notes that using large finite limits, like 1e6, feels inadequate and questions how to determine an appropriate cutoff without prior knowledge of the function.
  • Another participant emphasizes the difficulty of proving convergence for infinite integrals and suggests that approximating "unreasonably large" results as infinity might be a practical approach.
  • A different participant highlights their own challenge of knowing how far to extend the limits for convergence, questioning whether values like 1000 or 1,000,000 would suffice.
  • One suggestion involves changing variables to transform the infinite range into a finite one, referencing a specific technique from "Numerical Recipes."

Areas of Agreement / Disagreement

Participants express differing perspectives on the nature of the problem, with some focusing on the challenge of determining appropriate limits for convergence, while others discuss methods for transforming the integration range. No consensus is reached on a single solution or approach.

Contextual Notes

Participants acknowledge the complexity of the problem, including the dependence on the specific functions being integrated and the lack of a universal method for determining convergence limits.

Who May Find This Useful

This discussion may be useful for programmers and mathematicians interested in numerical methods for integration, particularly in cases involving infinite limits.

daviddoria
Messages
96
Reaction score
0
I want to integrate a function in c++ - so I dug out some numerical integration functions. However, they do not produce the correct results when the limits are infinite.

Simply using 1e6 or something instead of infinity seems like a very "hack" solution... and I also don't know the function ahead of time so I wouldn't know if 1e3 is good enough? or do I need 1e8, etc.

Of course you can find the analytic integral and just evaluate it, but not if the function doesn't have an analytic integral!

What do people usually do to numerically evaluate infinite integrals?

Thanks!

Dave
 
Physics news on Phys.org
daviddoria said:
I want to integrate a function in c++ - so I dug out some numerical integration functions. However, they do not produce the correct results when the limits are infinite.

Simply using 1e6 or something instead of infinity seems like a very "hack" solution... and I also don't know the function ahead of time so I wouldn't know if 1e3 is good enough? or do I need 1e8, etc.

Of course you can find the analytic integral and just evaluate it, but not if the function doesn't have an analytic integral!

What do people usually do to numerically evaluate infinite integrals?

Thanks!

Dave

Computation falls pretty far short when it comes to doing general mathematics. To know that an integral is infinite is to know that the limit of the Riemann sums doesn't converge, which in the general case, requires an explicit proof. The best you can do is approximate and treat "unreasonably large" results as infinity. If you're clever, though, you might be able to find some nice heuristics for determining what values constitute "unreasonably large."
 
That's exactly the opposite problem! I know that these integrals converge, but I don't know how far I have to go until they come close enough to converging... is it 1000, or 100000, or 1000000 ?
 
daviddoria said:
That's exactly the opposite problem! I know that these integrals converge, but I don't know how far I have to go until they come close enough to converging... is it 1000, or 100000, or 1000000 ?

What kind of functions are you trying to integrate exactly? Perhaps there is a way to find or approximate an upper bound for some of them.
 
The standard trick is to make a change of variable that turns the infinite range of integration in the old integration variable into a finite range of integration in the new integration variable.

For example, after using t = e^{-x},

\int_{x=a}^{x=\infty}

becomes

\int_{t=0}^{t=e^{-a}}.

See 4.4. of Numerical Recipes,

http://www.nrbook.com/a/bookcpdf.php.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 43 ·
2
Replies
43
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K