Expectation of $Y := \min\{\frac{a}2, X\}$ if $X$ is uniform on $(0,a)$ The density of X is given by

$
f(x)=
\begin{cases}
 \frac{1}{a}&amp;\, 0 \leq x &lt; a\\
 0&amp;\, otherwise\\
\end{cases}
$ 

Y := min{$\frac{a}{2}$, X} so Y belongs to [0, $\frac{a}{2}$]

Based on this solution, $E(Y) = \frac{3a}{8}$. Why is $E(Y) = \frac{3a}{8}$?

My Work

$
F_Y(y)=
\begin{cases}
 \frac{y}{a}&amp;\, 0 \leq y &lt; \frac{a}{2}\\
 1&amp;\, y \geq \frac{a}{2}\\
\end{cases}
$ 

$
(F_Y(y))' = f_Y(y)=
\begin{cases}
 \frac{1}{a}&amp;\, 0 \leq y &lt; \frac{a}{2}\\
 0&amp;\, y \geq \frac{a}{2}\\
\end{cases}
$ 

$
E(Y) = \int_{0}^{\frac{a}{2}} yf(y) dy = \int_{0}^{\frac{a}{2}} \frac{y}{a} dy = \frac{a}{8}
$
The cdf $F_Y(y)$ of variable $Y$ is not continuous, so $Y$ doesn't have a density. Thus differentiating $F_Y$ gives the wrong answer. The linked solution is using the formula
$$
E(h(X)) = \int_{-\infty}^\infty h(x) f(x)\,dx
$$
with $h(x):= \min\{\frac a2, x\}$. This gives
$$
E[Y]=E[h(X)]=\int_{-\infty}^{a/2}x \,f(x)\, dx + \int_{a/2}^\infty \frac a2 \,f(x)\,dx
$$
since $\min\{\frac a2, x\}$ equals $x$ when $x$ is less than $\frac a2$, and equals $\frac a2$ when $x$ exceeds $\frac a2$. Now plug in the density $f(x)$ for $X$.
A different approach would be:

$$EY=E\left[Y|X&lt;\frac{1}{2}a\right]+E\left[Y|X\ge\frac{1}{2}a\right]= \int_0^{\frac{1}{2}a}x\frac{1}{a}dx= 0.125a+ 0.5a=\frac{3}{8}a$$

It relays on the properties of conditional expectations.