Expectation value of position of eigenstate of position

Consider a quantum system in an eigenstate $|x\rangle$ of the position operator $\hat{x}$, which means that $\hat{x}|x\rangle=x|x\rangle$. I hope that the expected value of $\hat{x}$ will be $x$, since the state $|x\rangle$ is the one in which the system is located in the position $x$. To prove it we do the following: \begin{equation} \langle \hat{x} \rangle = \langle x|\hat{x}|x\rangle = \langle x|x|x\rangle = x\langle x|x\rangle \end{equation} Now, $\langle x'|x\rangle=\delta(x-x')$, so I think that $\langle x|x\rangle$ would be $+\infty$?, and then: \begin{equation} \langle \hat{x} \rangle = \pm\infty?\quad (\text{depending on the sign of $x$}) \end{equation} Which is clearly wrong. How do you calculate this mean value?

• @JohnForkosh Sorry, but you're wrong. The inner product involves integral of the wavefunction squared. – OON Sep 4 '17 at 3:03

The formula for the expectation value $\langle A\rangle=\langle\psi|\hat{A}|\psi\rangle$ is given for the normalized states $\langle\psi|\psi\rangle=1$. You can generalize it as \begin{equation} \langle A\rangle=\frac{\langle\psi|\hat{A}|\psi\rangle}{\langle\psi|\psi\rangle} \end{equation} Of course this expression would still be ill-defined for $|x\rangle$ as it's not a proper quantum state, just as $\delta(x-x')$ is actually not a function but rather a distribution.
The spectrum of the position operator is purely continuous, and that means that there is no eigenvector for it in $L^2(\mathbb{R})$. Its eigenvectors are in fact in the space of tempered distributions $\mathscr{S}'(\mathbb{R})\supset L^2(\mathbb{R})$. Nonetheless, there are "almost eigenvectors" of $\hat{x}$ in $L^2$:
Given any $\epsilon>0$ and $x_0\in \mathbb{R}$, there exists at least one (actually many) vector $\psi_{x_0,\epsilon}\in L^2$ such that: $$\int_{\mathbb{R}}x\; \bar{\psi}_{x_0,\epsilon}(x)\psi_{x_0,\epsilon}(x)\;\mathrm{d}x=x_0\; ,\; \int_{\mathbb{R}} \bar{\psi}_{x_0,\epsilon}(x)\psi_{x_0,\epsilon}(x)\;\mathrm{d}x =1\; ,$$ and $\mathrm{supp}(\psi_{x_0,\epsilon})\subseteq [x_0-\epsilon,x_0+\epsilon]$.
Such function is extremely localized around $x_0$ (so it is almost an eigenfunction of $\hat{x}$ with eigenvalue $x_0$), it is normalized, and has the "right" expectation (for it to be an eigenfunction). Finally, the limit $\epsilon\to 0$ of $\psi_{x_0,\epsilon}$ (in the sense of distributions) yields the "correct" (generalized) eigenfunction $\delta(x-x_0)$ (that is however not normalizable since not in $L^2$).