Let $f_{a,b}(x)=(\frac{x}{4}-\frac{1}{2})\boldsymbol{1}_{(a,b)}(x)$, with $\boldsymbol{1}$ is the indicator function.
For which $a,b \in \mathbb{R}$ is $f$ a probability density function? Also, how to compute the expected value?
I tried this:
Since the function $\frac{x}{4}-\frac{1}{2}$ has a root at $x=2,$ I integrated from $b$ to $2$:
$\int_{b}^{2} \frac{x}{4}-\int_{b}^{2} \frac{1}{2} dx=1$
$\left[\frac{x}{4}-\frac{1}{2}\right]_b^2=1$
$\left[\frac{x^3}{3}+x\right]_1^2=1$
$=-\frac{b^2}{8}-\frac{1}{2}b-\frac{1}{2}$
I put $2$ in the formula: $2(\frac{1}{2}-\frac{1}{8}a)-1=0$ and got $2+\sqrt{8}.$
Now I'm not sure how to continue from here.
Your function is a probability density function if it is positive and its integral over $\mathbb{R}$ is $1$.
Positivity:
$f$ is positive iff :
$$ \forall x \in \mathbb{R}, (\dfrac{x-2}{4}) \mathbb{1}_{(a, b)} (x) \geq 0 $$
$\Leftrightarrow$
$$ \forall x \in (a, b), (\dfrac{x-2}{4}) \mathbb{1}_{(a, b)} (x) \geq 0 $$
$\Leftrightarrow$
$$ \forall x \in (a, b), \dfrac{x-2}{4} \geq 0 $$ $\Leftrightarrow$
$$ \dfrac{a-2}{4}\geq 0 \textrm{ and } \dfrac{b-2}{4}\geq 0 $$
$\Leftrightarrow$
$$ a, b \geq 2 $$
Integral is $1$
$$ \int_{\mathbb{R}}f = \int_{a}^b \dfrac{x-2}{4} dx = \dfrac{1}{16} (b - a) (b+a - 4) $$
So we must have $(a, b)$ belong to some hyperbola. See here for the definition of hyperbola.