Task from an old exam (but in German):
Given is $Y \sim f $ with density $f(x) = \left\{\begin{matrix} \frac{1}{2}\cos(x) \text{ }\text{ }\text{ if } x \in \left[-\frac{\pi}{2}, \frac{\pi}{2}\right]\\ 0 \text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ else } \end{matrix}\right.$
Determine the expected value $E(X)$ and the variance $Var(X_i).$
I'm preparing for an exam. I know how to determine $E(X)$ and $Var(X)$ if we got a matrix given but no idea about this task with density : /
But I think you need to integrate that one function inside this density which has intervals, so:
$$\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}{\frac{1}{2}\cos(x)\text{ } dx} = \left [\frac{1}{2} \sin(x) +c \right ]_{-\frac{\pi}{2}}^{\frac{\pi}{2}} = \frac{1}{2} \sin\left(\frac{\pi}{2}\right)+c - \left(\frac{1}{2}\sin\left(-\frac{\pi}{2}\right)+c\right) = \frac{1}{2}+\frac{1}{2}=1$$
How do you get the expected value and variance from it? :s
Hint: By the definitions, expectation is given by $$\text{E}(X) = \int_{-\infty}^\infty x f(x) \, dx$$ and variance is given by $$\text{Var}(X) = \int_{-\infty}^\infty x^2 f(x) \, dx - \text{E}(X)^2.$$ So you're going to need to integrate $\frac{1}{2} x \cos x$ and $\frac{1}{2} x^2 \cos x$ on the prescribed interval; in both cases you can use symmetry to make your task easier, since the former function is odd and the latter is even.