# Numerical integration with divergent bounds

I have an ugly numerical function $f(x)$ that diverges at the boundaries $x_a$ and $x_b$, but I want to calculate the integral, $$\int_{x_a}^{x_b} f(x) dx$$ For physical reasons I know that the integral needs to be convergent, but I don't know how to calculate it.

I have a series of values $g_1, g_2, ..., g_n$ corresponding to points $x_1, x_2, ..., x_n$. This is a smooth function which I can spline interpolate to be $g(x)$. This function is zero at the points $g(x_a) = g(x_b) = 0$ --- in particular it changes sign at these points, with $g(x_a < x < x_b) > 0$.

The function I need to integrate is $f(x) = 1/\sqrt{g(x)}$, which then diverges at $x_a$ and $x_b$.

edit:

My initial approach was to divide the region $[x_a,x_b]$ into three regions, $R_1:[x_a,x_a + \delta]$, $R_2:[x_a + \delta, x_b - \delta]$, $R_3:[x_b - \delta, x_b]$ and break each of these regions into $n$ intervals. Region $R_2$ is very well behaved, and I can easily calculate the integral using a Riemann sum with something like $n = 100$ segments.

To evaluate the accuracy of my integrals over the boundary regions, I compared left and right Riemann sums. As I decreased $\delta$, however, the difference between my Riemann sums diverged.

• What are $f(x)$, $x_1$ and $x_2$?
– user207710
Commented Feb 7, 2015 at 21:34
• More details may be needed. Commented Feb 7, 2015 at 21:34
• @zhermes. Just because the function is not defined at its boundary points, doesn't mean that it can not be integrated. The answer to the (rather improper) integral may be of convergent nature Commented Feb 7, 2015 at 21:46
• @imranfat thats basically what I've already said. But, for the simplest numerical methods, you must evaluate your function at (or near) your endpoints to evaluate the integral. Commented Feb 7, 2015 at 21:52
• My previous statement was too general: $\sqrt{1-x^2} f(x)$ will not be bounded if, say, $f(x)=(1-x)^{-2/3}$. Yet such a function is still integrable. Chebyshev-Gauss quadrature will work very well provided the divergence at the boundary is like the divergence of $x^{-1/2}$. It will still work better than, say, Gauss-Legendre quadrature if the divergence is more rapid than this, because it will put more nodes near the boundary.
– Ian
Commented Feb 11, 2015 at 5:52

I have an ugly numerical function $f(x)$ that diverges at the boundaries $x_1$ and $x_ 2$

For integrating this functions use a well-known numerical integration method (e.g. Simpson approximation), but for the Region in which the integral diverges, you can choose more coarse discretization intervals. That means you have a large number of interval subdivisions in the interior of the integral, but near boundary you can use very few subdivisions to "average out" your divergences.

• Thanks, that's what I tried first --- but as I make the poorly-behaved regions smaller, the difference between left and right reimann sums diverges... so I still wasn't getting a good approximation Commented Feb 7, 2015 at 21:39
• @zhermes You can automate adaptive quadrature using methods based on Richardson extrapolation. (Basically, you estimate the error using a Richardson method, and if it is too big, you make the subintervals smaller.)
– Ian
Commented Feb 7, 2015 at 22:31

A specific formula for $f(x)$ is needed before the question can be answered. Take for example $$\int_1^2\dfrac{x}{\sqrt{x^3-1}}\mathrm d x.$$ This doesn't have a closed-form formula for its value. If you try to integrate it numerically, you have a problem, because the function is unbounded at the lower limit. However, a substitution $x=\sec^{2/3}\theta$ converts this "improper" integral into a proper one: $$\dfrac23\int_0^{\arccos(1/\sqrt8)}\dfrac{1}{\cos^{4/3}\theta}\mathrm d\theta,$$ which has a bounded argument and is easily amenable to numerical integration. Perhaps your function $f$ will allow a similar trick with a suitable substitution.

• Thanks! But I don't have an analytic expression for my function, it is purely numeric. I will amend my question to explain better. Commented Feb 7, 2015 at 21:57
• @zhermes: How do you evaluate your function if you do not have an expression for it? It's not enough to calculate it for a few values of $x$ near to the limit, because values even closer to the limit may make an important contribution to the integral. Could you perhaps find a mathematically explicit function which approximates your function asymptotically well as the limit is approached? Commented Feb 7, 2015 at 22:14