I have the following stepwise function: $$f(x) = \begin{cases} \frac{1}{3} & -1\le x \lt 0 \\ \frac{2}{3} & 0 \le x \le 1 \\ 0 & \text{otherwise} \end{cases} $$
I wonder how I can derive $E(X)$ and $Var(X)$ of a stepwise uniform function using the integral. If I draw it I would say the mean is at $x = 1/4$ (as then the area below the function equals $0.5$). But when I am integrating it I get $1/6$.
Can someone help me and show how I properly solve this question?
Thanks a lot!
Here is a start:
$$\mu = E(X) = \int_{-1}^1 xf(x)\,dx = \int_{-1}^0 x(1/3)\,dx + \int_0^1 x(2/3)\,dx = \dots\,.$$ Find $E(X^2)$ similarly, and use $Var(X) = E(X^2) - \mu^2.$