# Expectation of discontinuous functions of random variables

I might be missing something very basic, but I have the following scenario. Consider the random variable:

$$X \sim Exp(1)$$

and call the pdf as $f(x)$. Define a function of this random variable as:

$$g(X) = \begin{cases} 0 & if \ X=0 \\ 1 & if \ X \in(0,3) \\ 1 + 0.4(X-3) & if \ X\geq3 \end{cases}$$

How can I find $E(g(X))$? I as far as I know there is a the rule for expectations that say

$$E(g(X)) = \int_{-\infty}^{+\infty} g(x)f(x) dx$$

But I am not sure how to apply this here. I thought about splitting this integral as:

$$\int_0^0{0f(x)dx} + \int_0^3{1f(x)dx} + \int_3^\infty{\left[1 + 0.4(X-3)\right]f(x)dx}$$

(of course the first one is 0, but I left it there just to be more formal). So my questions are: (1) does this work? (2) is there any shortcut I'm missing, perhaps using some property of the exponential distribution?

• Actually, $g(x)$ is undefined for $x < 0$, but assuming that it has finite value for all $x < 0$, the correct decomposition should have $\int_{-\infty}^0 g(x)f_X(x) dx = \int_{-\infty}^0 0 dx = 0$ as the first term since for all $x \in (-\infty,0]$, either $g(x)$ or $f(x)$ is known to be $0$. Of course, what you have has just skipped over part of this which is OK too. Nov 23, 2016 at 12:59

This decomposition of the expectation is better understood via indicator functions: write $g(x)$ as $$g(x)=0\mathbb{I}_0(x)+1\mathbb{I}_{(0,3)}(x)+\{1+0.4(x-3)\}\mathbb{I}_{(0,3)^c}(x)$$Then \begin{align} \mathbb{E}[g(X)]&=\mathbb{E}[0\mathbb{I}_0(X)+1\mathbb{I}_{(0,3)}(X)+\{1+0.4(X-3)\}\mathbb{I}_{(0,3)^c}(X)]\\&=\mathbb{E}[0\mathbb{I}_0(X)]+\mathbb{E}[1\mathbb{I}_{(0,3)}(X)]+\mathbb{E}[\{1+0.4(X-3)\}\mathbb{I}_{(0,3)^c}(X)]\\ \end{align} by linearity of the expectation. Now,$$\mathbb{E}[0\mathbb{I}_0(X)]=0$$because the exponential distribution is absolutely continuous wrt Lebesgue measure, hence has no atom (i.e., puts no mass on specific values like $0$). And $$\mathbb{E}[1\mathbb{I}_{(0,3)}(X)]=\int1\mathbb{I}_{(0,3)}(x)\exp\{-x\}\text{d}x=\int_0^3\exp\{-x\}\text{d}x=1-\exp\{-3\}$$while \begin{align}\mathbb{E}[\{1+0.4(x-3)\}\mathbb{I}_{(0,3)^c}(X)]&=\int\{1+0.4(x-3)\}\mathbb{I}_{(0,3)^c}(x)\exp\{-x\}\text{d}x\\&=\int_3^{\infty}\{1+0.4(x-3)\}\exp\{-x\}\text{d}x\\&=\exp\{-3\}+0.4\int_0^\infty x\exp\{-(x+3)\}\text{d}x\\&=\exp\{-3\}+0.4\exp\{-3\}\int_0^\infty x\exp\{-x\}\text{d}x\\&=\exp\{-3\}+0.4\exp\{-3\}\end{align}This leads to$$\mathbb{E}[g(X)]=1+0.4\exp\{-3\}$$