The graph of the density function of the random variable $X$ is an isosceles triangle with basis the intervall $[-1/2,1/2]$. Which is the variance $s^2(X)$ ?
I have done the following:
It is $s^2(X)=E(X^2)-(E(X))^2$.
We consider the funcion $$f(x)=\begin{cases}\frac{1}{4}(x+1/2) & \text{ for } -1/2\leq x\leq 0 \\ \frac{1}{4}(1/2-x) & \text{ for } 0\leq x\leq 1/2 \\ 0 & \text{ otherwiese }\end{cases}$$ Then we use the definition of the expected value.
Is the function $f$ correct?
You should replace $\frac 1 4$ by $4$. As it stands, your function does not integrate to $1$. The variance is $\int x^{2}f(x)dx-(\int xf(x)dx)^{2}$.