TITLE: Expected Value Function
QUESTION [8 upvotes]: My text-book defines expected value as
$$E(X) = \mu_x = \sum_{x \in D} ~x  \cdot p(x)$$ 
And so, if I was to find the expected value of a random variable $X$, where $X = 1,2,3$, then it would resemble this: 
$$E(X)= \sum_{x=1}^3~ x \cdot p(x)= 1\cdot p(1) + 2\cdot p(2) + 3 \cdot p(3)$$ 
Furthermore, if I wanted to calculate $E(X^2)$, it would be $E(X^2) = 1^2 \cdot P(1) + 2^2 \cdot p(2) + 3^2 \cdot p(3)$. My question is, why don't we square the x-values in the probability function $p(x)$? 
Also, is computing the expected value a way of calculating the average of the random variable? It seems a little odd to calculate it that way.
PS: If any use of notation, or vocabulary, is incorrect, please inform me.

REPLY [2 votes]: There were two questions. The first question: Why don't we square the $x$ values in the calculation for the expected value of $X^2$.
Suppose $Y = g(X)$.
\begin{equation}
\begin{aligned}
E(Y) & \stackrel{\text{(a)}}{=} \sum_{y\in{S_Y}}yP_Y(y)\\
& \stackrel{\text{(b)}}{=} \sum_{y\in{S_Y}}y\sum_{x:g(x) = y}P_X(x)\\
& \stackrel{\text{(c)}}{=} \sum_{y\in{S_Y}}\sum_{x:g(x) = y}yP_X(x)\\ 
& \stackrel{\text{(d)}}{=} \sum_{y\in{S_Y}}\sum_{x:g(x) = y}g(x)P_X(x)\\
& \stackrel{\text{(e)}}{=} \sum_{x\in{S_X}}g(x)P_X(x)\\
\end{aligned}
\end{equation}
(a): The definition of expected value of a discrete random variable, as you have supplied.
(b): Because the probability of random variable $Y$ taking on a value $g(x)$ is equal to the sum of the probability of all the values of $x$ which will map to $g(x)$.
(c): Interchanging the summation.
(d): Because of the condition in the summation, we can replace $y$ by $g(x)$.
(e): Because enumerating across all $y$, then enumerating across all $x$ such that $g(x) = y$, is equivalent to enumerating across all $x$ since every $x$ must map to exactly one $y$. (Multiple $x$ could map to the same $y$).
So, in your instance, set $g(x) = x^2$ to obtain the result.
The second question: Why is expected value defined the way it is defined?
Expected value can be thought of as the center of mass, if we set $P_X(x)$ to be the mass located at a distance $x$ from the origin. It corresponds exactly with the arithmetic average when the distribution of $X$ is uniform.