TITLE: An example of an infinitely differentiable function with compact support
QUESTION [9 upvotes]: Could anyone give me a function infinitely differentiable on the real line and having a compact support? And the function must be nonnegative and normalized, i.e. the integration of the function on the real line must be one.
I tried to think of one myself, but it seems trickier than expected.

REPLY [5 votes]: Fix $\varepsilon>0$ as small as you want and take $\frac{f}{\|f\|_{L^1}}$ with
$$f(x)=\begin{cases}1&-\varepsilon\leq x\leq \varepsilon\\
\exp\left(-\frac{(|x|-\varepsilon)^2}{4\varepsilon^2-x^2}\right)&\varepsilon\leq |x|\leq 2\varepsilon\\
0&|x|\geq 2\varepsilon
\end{cases}.$$
Here an example for $\varepsilon=1/2$ ($f$ is not normalized):