Numerical Integration – Trying to Rewrite a Function but Can't Get Rid of Singularities. Thank you for reading.
I've come to the realization that I'm completely pants at calculus. I'm struggling with integrating a function numerically. I know how to program an integration in Matlab but the function for which I am to integrate needs to be rewritten in order to do so over $0$ to $\infty$. I'm guessing the problem has an obvious answer for many of you, and I've seen examples of successful substitutions for other problems, but given my lacking math skills I'm afraid this is completely over my head.
The function:
$$\int_0^\infty \frac{1 - e^{-x^2}}{2x^2}\,dx.$$
The problem:
No matter what substitution I try I either still have to divide by $0$ somewhere or I end up with something that is questionable at best, or something that will diverge to infinity, and thus of course useless to me anyway.
The problem has a hint of sorts that says one should analyze what the function is at $x = 0$. Once again I'm considerably doubtful that I've arrived at something I can trust to be valid. And even if I were to get something useful from the small hint here I'm not sure how that would help me with the overall problem.
Any insights, inputs, or feedback to my problem are greatly appreciated! And thank you for reading!
 A: You can use the substitution
$$
x = \frac{1}{1-t}
\,.
$$
Then, $x([0, 1)) = [0, \infty)$. Furthermore, $x(t)$ is monotonically increasing. We have that
$$
\mathrm{d}x = \frac{\partial x}{\partial t} \mathrm{d}t = \frac{1}{(1-t)^2} \mathrm{d}t
\,,
$$
implying
$$
\int_0^\infty \frac{1 - e^{-x^2}}{2 x^2} dx
= \int_0^1 \frac{1 - e^{-\frac{1}{(1-t)^2}}}{2 \frac{1}{(1-t)^2}} 
\frac{1}{(1-t)^2} \mathrm{d}t
= \int_0^1 \frac{1 - e^{-\frac{1}{(1-t)^2}}}{2} \mathrm{d}t
\,.
$$
This integral can be approximated using a simple quadrature scheme.
A: Well, let $$I=\int_0^\infty\frac{1-e^{-x^2}}{x^2}dx$$
Then, we need to calculate:
$$J=\int_0^\infty\frac{1-e^{-x^2}}{2x^2}=\frac{I}{2}$$
So, by integration by parts, because $\left(-\frac{1}{x}\right)'=\frac{1}{x^2}$, we have:
$$\begin{align*}
I=&\int_0^\infty\left(-\frac{1}{x}\right)'(1-e^{-x^2})dx=\left.-\frac{1}{x}(1-e^{-x^2})\right|_0^\infty-\int_0^\infty-\frac{1}{x}(1-e^{-x^2})'dx=\\
=&-\lim_{x\to+\infty}\frac{1-e^{-x^2}}{x}+\lim_{x\to0}\frac{1-e^{-x^2}}{x}+\int_0^\infty\frac{1}{x}(2x)e^{-x^2}dx=\\
=&\frac{1-0}{+\infty}-\left.\frac{d(e^{-x^2})}{dx}\right|_{x=0}+2\int_0^\infty e^{-x^2}dx=\\
=&\ 0-\left.(-2xe^{-x^2})\right|_{x=0}+\sqrt{\pi}=2\cdot0\cdot e^{-0}+\sqrt{\pi}=\\
=&\sqrt{\pi}
\end{align*}$$
So
$$J=\frac{I}{2}=\frac{\sqrt{\pi}}{2}$$
A: Thank you everyone for your answers to my problem. From your answers I see I have to change my understanding of the rule of never to divide by 0. As I understand it I can divide by 0 if it's enclosed in a partial function that becomes 0.
Again, thank you! Regards / euro
