Please explain to me why the Expected Value is $ E[X] = \int_{-\infty}^{\infty} x f_X(x) dx $ For probability density functions (at least for the normal distribution and beta distribution) it holds that the expected value is given by $ E[X] = \int_{-\infty}^{\infty} x f_X(x) \, dx $.
I have to solve this for a homework for the beta distribution. Finding a solution on the internet wasn't that hard but I wouldn't mind understanding this calculation.
I'd like to know first why $ f_X(x) $ is multiplied by $ x $. The same thing is done if the variance gets calculated - but in this case the function gets multiplied by $ x^2 $. So why is this the case?
The other thing is that I don't even understand why this function gets integrated and not derived e.g.?
Could anyone explain this to me? I am not looking for a solution, just an explaination. Thank you.
 A: Instead of thinking of it as
$$
\Big(xf_X(x)\Big)\,dx,
$$
one can think of it as
$$
x\Big(f_X(x)\,dx\Big).
$$
The point is that $f_X(x)\,dx$ is the infinitely small probability that the random variable $X$ is in an infinitely small interval that includes $x$, where $dx$ is the length of that interval.  Thus this is analogous to the discrete situation where you find $\displaystyle\sum_x x\Pr(X=x)$.  One thinks of integrals as the sum of infinitely many infinitely small quantities.
There's also a logically rigorous point of view that would explain why it is that if
$$
\Pr(X\in A) = P(\{\omega\in\Omega : X(\omega)\in A\}) = \int_A f(x)\,dx
$$
for every measurable set $A$, then
$$
\mathbb E(X) = \int_\Omega X(\omega)\,P(d\omega) = \int_{-\infty}^\infty xf(x)\,dx.
$$
I'll come back later with something about that unless someone beats me to it.  And if someone does, I might post my own p.o.v. anyway.
A: What if our random variable only took finitely  many values, say $x_1,\ldots,x_n$? Then we would say that
$$
\mathbb{E}[X]=x_1\cdot P(X=x_1)+\cdots+x_n\cdot P(X=x_n).
$$
When we have a continuous distribution, about the best that we can do is to come up with a nice approximation as if it took only finitely many values. 
For the moment, let's suppose that our random variable lives on a bounded interval $I$. (To get to the general case, we basically take limits.)
We can break $I$ up in to VERY SMALL intervals $(x_0,x_1),(x_1,x_2),\ldots,(x_{n-1},x_n)$. If the intervals are small, then one end point and the other don't differ by very much. So, we could approximate the expectation by
$$
\mathbb{E}[X]\approx x_1\cdot P(X\in(x_0,x_1))+\cdots+x_n\cdot P(X\in (x_{n-1},x_n)).
$$
But, we know that $P(X\in (x_{i-1},x_i))=\int_{x_{i-1}}^{x_i}f_X(x)\,dx\approx f_X(x_i)\Delta x_i$, where $\Delta x_i=x_i-x_{i-1}$. So, in all,
$$
\mathbb{E}[X]\approx \sum_{i=1}^{n}x_i\,f_X(x_i)\Delta x_i...
$$
but this looks like a Riemann sum!  If we let $n\rightarrow\infty$ and the intervals shrink down, this approaches precisely
$$
\int_a^bx\,f_X(x)\,dx,
$$
where $I=(a,b)$.
A: A complete answer involves measure spaces and that's maybe a bit heavy (and given the details of this question you may find it a bit unsatisfying). What I will do instead is draw an analogy. 
Recall that an integral is a limit of sums. For simplicity's sake we will not use the full power of the Riemann integral but just assume that the partitions are uniform: 
$$\int _a^b g(x)\,dx = \lim_{n\to\infty} \left(\sum_{k=1}^n g\left(a+\textstyle\frac{b-a}nk\right)\right)$$
In essence, then, an integral is like a "summation over the reals".
We know that in the case of finite sums, an expected value is $E[X] = \sum xf(x)$, where the sum is over all elements in the event space and $f$ is the probability distribution function. If we believe the integral is a summation over the reals, then this translates perfectly to show that $E[X]$ becomes $\int xf(x)\,dx$ when $X$ happens to be continuous.
If you don't believe the analogy is so strong, we can do a bit better by thinking of approximating the random variable. For instance, we maybe only have a device that reads 4 decimal places so that the outcome $5.3$ is indistinguishable from $5.30002$. Then if the smallest outcome in the event space of $X$ is $a$ and the largest is $b$, we can partition the interval into $n$ pieces so that $\frac{b-a}{n}<0.0001$. It is a good exercise to see that you get $\sum_{k=1}^n (a+\frac{b-a}nk)\cdot f\left(a+\textstyle\frac{b-a}nk\right)$. 
This you should recognize as the RHS of the centered equation above but without the limit. The limiting process then corresponds to taking better and better approximations of your "perfect" random variable $X$, and the end result is $\int _a^b xf(x)\,dx$ which recovers the formula you were given.
A: For a discrete probability function (like the number of times a coin flip results in heads), the expected value of the function is the sum of each possible result times the probability of that result.  The integral is just the natural transition from a discrete function to a continuous function.
A: Euristically, the expected value for a discrete random variables is its weighted mean. For this reason the expected value is the sum of each value multiplicated by the probability. 
For continues r.v. the problem is a bit more awkward because you have to consider an integral in the Lebesgue-Riemann sense. In other words $$E[X]= \sum_{i} x_{i} p_{i},$$ for discrete a.v. and $$E[X]=\int_{\Omega} X(\omega) d \mu (\omega)$$ for continues a.v. (and in general), where $\Omega$ is the probability space.
