Evaluating integral with a singularity. 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.
 A: 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.)
A: Attempting to evaluate the integral
$$\int_{-10}^{10} \frac{1}{x-2}\ \mathrm dx=\int_{-12}^{8} \frac{1}{t}\ \mathrm dt$$
$$=\lim\limits_{\alpha\to 0}\int_{-12}^{\alpha} \frac{1}{t}\ \mathrm dt+\lim\limits_{\beta\to 0}\int_{\beta}^{8} \frac{1}{t}\ \mathrm dt$$
Both integrals diverge, which implies that
$$\int_{-10}^{10} \frac{1}{x-2}\ \mathrm dx=\mbox{nonexistent}$$
Evaluating the Cauchy principal value of the integral
$$\mathrm{PV}\int_{-10}^{10} \frac{1}{x-2}\ \mathrm dx=\mathrm{PV}\int_{-12}^{8} \frac{1}{t}\ \mathrm dt$$
$$=\lim\limits_{\gamma\to 0^+}\left[\int_{-12}^{-\gamma} \frac{1}{t}\ \mathrm dt+\int_{\gamma}^{8} \frac{1}{t}\ \mathrm dt\right]$$
$$=\lim\limits_{\gamma\to 0^+}\left[\int_{\gamma}^{8} \frac{1}{t}\ \mathrm dt-\int_{\gamma}^{12} \frac{1}{t}\ \mathrm dt\right]$$
$$=\lim\limits_{\gamma\to 0^+}\left[\int_{\gamma}^{8} \frac{1}{t}\ \mathrm dt-\int_{\gamma}^{8} \frac{1}{t}\ \mathrm dt-\int_{8}^{12} \frac{1}{t}\ \mathrm dt\right]$$
$$=-\int_{8}^{12} \frac{1}{t}\ \mathrm dt=-\ln\left(\frac{3}{2}\right)=\ln\left(\frac{2}{3}\right)$$
Which method should you use in your code?
In this case the improper integral simply does not exist. Therefore your only option is to assign the nonexistent integral a value via the method of Cauchy principal value. 
