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

  • Thread starter Thread starter daviddoria
  • Start date Start date
  • Tags Tags
    Infinite Integrals
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.
 
Back
Top