TITLE: numerical evaluation of an integral
QUESTION [7 upvotes]: I have this integral:
$$\int_{-1}^{1} \frac{e^x}{\sqrt{1-x^2}}\,dx$$
How can I get rid of the infinities at the ends of the interval so that I can evaluate this integral numerically? I tried to make some substitutions but didn't succeed.

REPLY [7 votes]: There are many ways to evaluate this numerically. Let $$I = \int_{-1}^1 \dfrac{e^x}{\sqrt{1-x^2}}dx$$
One way, I can think of is as follows. Set $x = \sin(\theta)$. We then get that
$$I = \int_{-\pi/2}^{\pi/2} e^{\sin(\theta)} d \theta$$ Once you have it in this form, you could recognize this is the modified Bessel function evaluated at $1$. To evaluate this numerically, expand $e^{\sin(\theta)}$ in a series.
We have
$$I = \int_{-\pi/2}^{\pi/2} \sum_{k=0}^{\infty} \dfrac{\sin^k(\theta)}{k!} d \theta = \sum_{k=0}^{\infty} \int_{-\pi/2}^{\pi/2} \dfrac{\sin^k(\theta)}{k!} d \theta = \sum_{k=0}^{\infty} \int_{-\pi/2}^{\pi/2} \dfrac{\sin^{2k}(\theta)}{(2k)!} d \theta\\
 = 2\sum_{k=0}^{\infty} \int_{0}^{\pi/2} \dfrac{\sin^{2k}(\theta)}{(2k)!} d \theta$$
Now recall that $$\int_0^{\pi/2} \sin^{2k}(\theta) d \theta = \dfrac{2k-1}{2k} \dfrac{2k-3}{2k-2} \cdots \dfrac12 \dfrac{\pi}{2} = \dfrac{(2k)!}{4^k k! k!} \dfrac{\pi}2$$
Hence, we have
$$I = \pi \sum_{k=0}^{\infty} \dfrac1{4^k \cdot (k!)^2}$$
The series converges at an exponential rate, hence truncating the series after a few terms should give you a very good accuracy.

REPLY [5 votes]: $$\int_{-1}^1 \frac{e^x}{\sqrt{1-x^2}}dx $$
$$ x = \sin t; dx=\cos t dt $$
$$\int_{-\frac{\pi}{2}}^{{\frac{\pi}{2}}} \frac{e^{\sin t}}{\sqrt{1-\sin^2 t}} \cos t dt$$
$$\int_{-\frac{\pi}{2}}^{{\frac{\pi}{2}}} e^{\sin t} dt$$
No more infinities.