[Math] Evaluating integral with a singularity.

integrationnumerical methodssingularity

I want to evaluate an integral numerically that contains one singularity. The software I use for this is Python. The actual integral I want to evaluate is quite long with a lot of other constants so I decided to present a different integral here which I think has the same problem.
$$
I = \int_{-10}^{10} \frac{1}{x-2} dx
$$

I tried to evaluate the integral in python using this code:

w = 2
def integrand(x,w):   
    return 1/(x - w)
ResultIntegral = quad(integrand,-10,10, args=(w))

Python indeed gives a warning when you run this code. Does someone know how to calculate such an integral numerically? What theorem or algorithm should I look into?

My solution attempt:

I have the idea that you should add an infinitesimal small imaginary number to the denominator of the integrand. (I saw this in a physics book, but the book does not go deeper into the matter than this). The integral would then become something like this:

$$
I = \lim_{\epsilon \rightarrow 0} \int_{-10}^{10} \frac{1}{x-2+i\epsilon } dx
$$

Somehow when you do something like this you can evaluate the integral. I tried modifying my python code:

w = 2
epsilon = 0.01*1j
def integrand(x,w,epsilon):   
    return 1/(x - w + epsilon)
Sigma = quad(integrand,-10,10, args=(w,epsilon))

I get an error in Python, this does not seem to work.

Best Answer

You have two problems.

The problem you ask about, why doesn't this code work, belongs somewhere other than MSE; it's not a math question. (When you ask this question again elsewhere you should say what the error message is...)

There's also confusion with the math. Strictly speaking there's no such thing as $$\int_{-1}^1\frac{dt}{t};$$you need to decide how to "interpret" this intergral. The most common interpretation would be $$\lim_{\epsilon\to0^+}\int_{\epsilon<|t|<1}\frac{dt}t,$$known as the "principal value" integral. This is not the same as $$\lim_{\epsilon\to0^+}\int_{-1}^1\frac{dt}{t+i\epsilon}.$$In fact here the principal-value integral is $0$, while that complex trick gives $i\pi$.

Which one is right? Neither. Because neither is actually equal to $\int_{-1}^1dt/t$; that integral simply does not exist. Which one do you want? That depends on why you think you want to find this integral in the first place. (But when one writes $\int_{-1}^1dt/t$ without expplanation, the most common interpretation is that the author meant the principal value, which again is not what that trick you read in a book gives.)

Related Question