The limit is infinite, so does not exist except in an extended sense.
* The function $x^n e^{-x}$ for $n = 1, 2, \dots$ is integrable over $[0,\infty)$.
Before showing this, we recall the fundamental theorem of calculus. The limit existing is the same as saying the limit of $F(M) - F(a)$ exists for an antiderivative of $f(x)$.
For this particular problem, it can be shown by integration by parts that for positive, integer values of $n$ that an antiderivative exists of the form $F(x) = p(x)e^{-x}$, where $p(x)$ is a polynomial of degree $n$. But we've seen that for any $n>0$, $\lim_{x \rightarrow \infty} x^n e^{-x} = 0$, so the same is true for any polynomial. So, $\lim_{M \rightarrow \infty} F(M) - F(1) = -F(1)$.
* The function $e^x$ is integrable over $(-\infty, a]$ but not
$[a, \infty)$ for any finite $a$. This is because, $F(M) = e^x$ and this has a limit as $x$ goes to $-\infty$, but not $\infty$.
* Let $f(x) = x e^{-x^2}$. This function has an integral over $[0, \infty)$ and more generally $(-\infty, \infty)$. To see, we note that as it is an odd function, the area from $0$ to $M$ is the opposite sign of that from $-M$ to $0$. So $\lim_{M \rightarrow \infty} (F(M) - F(0)) = \lim_{M \rightarrow -\infty} (F(0) - (-F(\lvert M\lvert)))$. We only then need to investigate the one limit. But we can see by substitution with $u=x^2$, that an antiderivative is $F(x) = (-1/2) \cdot e^{-x^2}$. Clearly, $\lim_{M \rightarrow \infty}F(M) = 0$, so the answer is well defined, and the area from $0$ to $\infty$ is just $e/2$. From $-\infty$ to $0$ it is $-e/2$ and the total area is $0$, as the two sides "cancel" out.
* Let $f(x) = \sin(x)$. Even though $\lim_{M \rightarrow \infty} (F(M) - F(-M) ) = 0$, this function is not integrable. The fact is we need *both* the limit $F(M)$ and $F(-M)$ to exist as $M$ goes to $\infty$. In this case, even though the area cancels if $\infty$ is approached at the same rate, this isn't sufficient to guarantee the two limits exists independently.
* Will the function $f(x) = 1/(x\cdot(\log(x))^2)$ have an integral over $[e, \infty)$?
We first find an antiderivative using the $u$-substitution $u(x) = \log(x)$:
```math
\int_e^M \frac{e}{x \log(x)^{2}} dx
= \int_{\log(e)}^{\log(M)} \frac{1}{u^{2}} du
= \frac{-1}{u} \big|_{1}^{\log(M)}
= \frac{-1}{\log(M)} - \frac{-1}{1}
= 1 - \frac{1}{M}.
```
As $M$ goes to $\infty$, this will converge to $1$.
* The sinc function $f(x) = \sin(\pi x)/(\pi x)$ does not have a nice antiderivative. Seeing if the limit exists is a bit of a problem. However, this function is important enough that there is a built-in function, `Si`, that computes $\int_0^x \sin(u)/u\cdot du$. This function can be used through `sympy.Si(...)`:
```julia;
@syms M
limit(sympy.Si(M), M => oo)
```
### Numeric integration
The `quadgk` function (available through `QuadGK`) is able to accept `Inf` and `-Inf` as endpoints of the interval. For example, this will integrate $e^{-x^2/2}$ over the real line:
```julia;
f(x) = exp(-x^2/2)
quadgk(f, -Inf, Inf)
```
(If may not be obvious, but this is $\sqrt{2\pi}$.)
## Singularities
Suppose $\lim_{x \rightarrow c}f(x) = \infty$ or $-\infty$. Then a Riemann sum that contains an interval including $c$ will not be finite if the point chosen in the interval is $c$. Though we could choose another point, this is not enough as the definition must hold for any choice of the $c_i$.
However, if $c$ is isolated, we can get close to $c$ and see how the area changes.
Suppose $a < c$, we define $\int_a^c f(x) dx = \lim_{M \rightarrow c-} \int_a^c f(x) dx$. If this limit exists, the definite integral with $c$ is well defined. Similarly, the integral from $c$ to $b$, where $b > c$, can be defined by a right limit going to $c$. The integral from $a$ to $b$ will exist if both the limits are finite.
##### Examples
* Consider the example of the initial illustration, $f(x) = 1/\sqrt{x}$ at $0$. Here $f(0)= \infty$, so the usual notion of a limit won't apply to $\int_0^1 f(x) dx$. However,
The cases $f(x) = x^{-n}$ for $n > 0$ are tricky to keep straight. For $n > 1$, the functions can be integrated over $[1,\infty)$, but not $(0,1]$. For $0 < n < 1$, the functions can be integrated over $(0,1]$ but not $[1, \infty)$.
As the limit does not exist, the function is not integrable around $0$.
* `SymPy` may give answers which do not coincide with our definitions, as it uses complex numbers as a default assumption. In this case it returns the proper answer when integrated from ``0`` to ``1`` and `NaN` for an integral over ``(-1,1)``:
* Suppose you know $\int_1^\infty x^2 f(x) dx$ exists. Does this imply $\int_0^1 f(1/x) dx$ exists?
We need to consider the limit of $\int_M^1 f(1/x) dx$. We try the $u$-substitution $u(x) = 1/x$. This gives $du = -(1/x^2)dx = -u^2 dx$. So, the substitution becomes:
```math
\int_M^1 f(1/x) dx = \int_{1/M}^{1/1} f(u) (-u^2) du = \int_1^{1/M} u^2 f(u) du.
```
But the limit as $M \rightarrow 0$ of $1/M$ is the same going to $\infty$, so the right side will converge by the assumption. Thus we get $f(1/x)$ is integrable over $(0,1]$.
### Numeric integration
So far our use of the `quadgk` function specified the region to
integrate via `a`, `b`, as in `quadgk(f, a, b)`. In fact, it can
specify values in between for which the function should not be
sampled. For example, were we to integrate $1/\sqrt{\lvert x\rvert}$
over $[-1,1]$, we would want to avoid $0$ as a point to sample. Here
is how:
```julia;hold=true
f(x) = 1 / sqrt(abs(x))
quadgk(f, -1, 0, 1)
```
Just trying `quadgk(f, -1, 1)` leads to a `DomainError`, as `0` will
be one of the points sampled. The general call is like `quadgk(f, a, b, c, d,...)`
which integrates over $(a,b)$ and $(b,c)$ and $(c,d)$,
$\dots$. The algorithm is not supposed to evaluate the function at the
endpoints of the intervals.
## Probability applications
A probability density is a function $f(x) \geq 0$ which is integrable
on $(-\infty, \infty)$ and for which $\int_{-\infty}^\infty f(x) dx =1$. The cumulative distribution function is defined by $F(x)=\int_{-\infty}^x f(u) du$.
Probability densities are good example of using improper integrals.
* Show that $f(x) = (1/\pi) (1/(1 + x^2))$ is a probability density function.
We need to show that the integral exists and is $1$. For this, we use the fact that $(1/\pi) \cdot \tan^{-1}(x)$ is an antiderivative. Then we have:
$\lim_{M \rightarrow \infty} F(M) = (1/\pi) \cdot \pi/2$ and as
$\tan^{-1}(x)$ is odd, we must have $F(-\infty) = \lim_{M \rightarrow
-\infty} f(M) = -(1/\pi) \cdot \pi/2$. All told, $F(\infty) -
F(-\infty) = 1/2 - (-1/2) = 1$.
* Show that $f(x) = 1/(b-a)$ for $a \leq x \leq b$ and $0$ otherwise is a probability density.
The integral for $-\infty$ to $a$ of $f(x)$ is just an integral of the constant $0$, so will be $0$. (This is the only constant with finite area over an infinite domain.) Similarly, the integral from $b$ to $\infty$ will be $0$. This means: