views:

151

answers:

3

Suppose I have an integral that's bounded on one (or both) end by (-)infinity. AFAICT, I can't analytically solve this problem, it takes brute force (e.g. using a Left Riemann Sum). I'm having trouble generalizing the algorithm so that it sets the proper subdivisions; I'll either do far too much work to calculate something trivial, or not do nearly enough and have huge aliasing errors.

Answering in any language is cool, but maybe someone with better google-fu can end this quickly. :)

Is what I'm looking for as impossible as trying to measure the British coastline?

A: 

If you're looking for an exhaustive solution, you'll probably need a symbolic math package of some kind. Reasons:

- If you're indeed looking for solutions to indefinite integrals (ones with no bounds at all, not just finite ones) then I don't know any other way except doing the digital equivalent of a lookup table or a symbolic algorithm (like knowing the integral of x^n dx is x^(n+1) / (n+1), plus an arbitrary expression that doesn't depend on x).

  • You can get somewhere with numeric integration on definite integrals. If one or both of the limits is +/- infinity, then you can probably approximate this with finite numbers that are "infinite enough," but then again, that gets you only so far as well, because what about things like the integral of 1/x from 1 to infinity? The answer is infinity, but it diverges as ln(x). There is no value that's "infinite enough" to give you the answer. Which leads back to a symbolic solution.
John at CashCommons
Why the downvote?
John at CashCommons
I was trying to explain when the Stackoverflow software said the answer had been deleted. Strange. The first bullet does not address the question. He said the integrand is analytically intractible. The suggestion in the second bullet is simply not a good one. See my answer and the one by Andrew Jaffe.
Jive Dadson
I guess I read the question differently. If the OP has one particular integral to calculate, then sure, put it into a form that can be done my numerical techniques. I saw the "exhaustive" tag and took that to mean that this was a more general problem than just plugging through one expression. The variable substitution is tailored to a particular problem. If the problem is a general one, then you're back at square one.
John at CashCommons
A: 

Use a change of variable. For example, x -> 1/x and note that the integral from a to b of f(x) dx is equal to the integral from 1/b to 1/a of (1/x^2)f(1/x) dx. Another handy one is the change of variable x -> -log(x), where the integral from a to infinity of f(x) dx is equal to the integral from 0 to e^(-a) of f(-log(x))/x dx.

Various open source packages contain routines to do this sort of thing. Someone else will have to recommend one, because I wrote my own when open source for math functions was non-existent.

The Numerical Recipes in C book is available online http://www.nrbook.com/a/bookcpdf.php You may be able to cobble something together from that. The chapter you are interested in is number 4. Be aware that array indexes are based off 1 rather than 0. Some of the algorithms could stand improvement, but I'll not go into that here.

Jive Dadson
+1  A: 

There are several ways to proceed, most of which involve trying to understand the behavior of your integrand. Often, there is a transformation x -> z(x) with a finite z(infinity) so you can transform your unbounded integral to a bounded one.

Also, it is often the case that you can analyze the "asymptotic" behaviour of the integrand as x goes to + and - infinity, so you can at least approximately work out the contributions from x>x+ and x< x- and then just do the definite integral between x- and x+.

There are plenty of good books on numerical integration. One that's used a lot in the physical sciences is Numerical Recipes. (Although you should rarely use the code directly!)

Andrew Jaffe
The polynomial interpolation that NRC uses for integration is not the best. In my ancient notes I find, "Substitute polint( for // polint(" Those indices are probably translated (by me) to base-0. NRC was transliterated from FORTRAN, and uses a trick to index arrays from 1.
Jive Dadson
I just poked into it a little more. The change I noted above is not the only one that's needed to clean up the NRC routines and make them converge faster. I have code to do the job. I've been thinking about contributing some of my stuff to the public domain, but you know how that goes. Something else is always more pressing.
Jive Dadson