How to express random variable $V(X)$ given function $V(x)$ I have come across a question which reads as follows:
For a random variable $X$ with mean $\mu$ and variance $\sigma^2 < \infty$, deﬁne the function $V (x) = E((X −x)^2)$ where $'E'$ denotes expectation. Express the random variable V (X) in terms of $\mu, \sigma^2$:
What I have so far: I am able to calculate $V(x)=\sigma^2+\mu2-2x\mu+x^2$
. The answer is $V(X)=\sigma^2+\mu2-2X\mu+X^2$. 
My question is why we can't substitute $X$ directly into the expression for $V$ to ge $E((X-X)^2)=0$?
 A: We actually have:$$V(x)=\int \left(X (\omega)-x\right)^2P(d\omega)$$
Now if I substitute $x=X(\omega)$ then this $\omega$ becomes a free variable on LHS but a  bound variable (ranging over $\Omega$) on RHS.
This is not allowed.

The situation is up to a certain level comparable with the following:
It is true in $\mathbb R$ that $\forall x\exists y\;[ x<y]$. 
Nevertheless something that is not true arises if we substitute $x=y+1$.
This because the free variable $y$ is placed on a spot where it is bound by quantifier $\exists y$.
A: $V(x)=E[(X−x)^2]$ is a function of $x$ and will vary with $x$.  Clearly it is non-negative, and you should be able to show that it is minimised when $x=\mu_X^{\,}$ the expectation (assuming $X$ has a mean) at which point $V(x_\mu)$ is $\sigma_X^2$ the variance of $X$.  
So if this variance is positive (i.e. $X$ is not almost surely constant), then $V(x)$ will be at least this much for all $x$.  Indeed you can say $V(x)=\sigma_X^2 + (x-\mu_X^{\,})^2$
This shows that (unless $X$ is almost surely constant) neither $V(x)$ nor $V(X)$ will be zero.   
Now that you know what $V(x)$ is as a function of $x$, you can apply it to a random variable.  So it is meaningful to talk about $V(X)$ as function of a random variable, remembering this too would be a random variable.  And indeed you would have  $V(X)=\sigma_X^2 + (X-\mu_X^{\,})^2$
Since $V(X)$ is a random variable, you can find its expected value.  This turns out tto be $E[V(X)]=2\sigma_X^2$.  None of this is affected by whether $X$ is a discrete or continuous random variable, though some of these statements assume $\sigma_X^2$ and $\mu_X^{\,}$ exist.
