Calculation of the mean value of energy in a wave function: proving that $\langle E \rangle_\psi = \sum_i P(E_i) E_i$ Let a wave function $\displaystyle \Psi(x) \equiv \frac{1}{Z}\sum_{i=1}^n \psi_i(x)$ with $n, Z \in \mathbb{R^+_0}$ such as $\displaystyle ||\Psi(x)||^2 \equiv \int_\mathbb{R} \Psi^\star(x).\Psi(x) \ dx = 1 = ||\psi_i(x)||^2$. Considering the Schrödinger equations $\displaystyle H\Psi = E\Psi \ \mathrm{and} \ H\psi_i = E_i\psi_i$, I would like to prove that:
$$\langle E \rangle_\psi \equiv \langle \Psi | H| \Psi\rangle \equiv \int_\mathbb{R}\Psi(x)^\star.H.\Psi(x) \ dx \equiv \int_\mathbb{R}\Psi^\star(x)\frac{-\hbar^2}{2m} \Delta\Psi(x) \ dx = \sum_{i=1}^n P(E_i)E_i$$
with $\displaystyle P(E_i) \equiv |\langle \psi_i | \Psi\rangle|^2 \equiv \left|\int_\mathbb{R}\psi_i^\star(x) \Psi(x) \ dx \right|^2$. I really have no idea how to proceed, I need to be able to use this formula to quickly calculate the mean value of the energy $E$ concidering a superposition of wave functions $\psi_i$ knowing $E_i$.
Do you have any idea of how to demonstrate that formula ?
 A: Like Photon suggested in the comments, do not plug in the position basis form of $H$. Instead, we can do this much more generally.
We consider the energy eigenstate expansion of $|\Psi\rangle$,
$$
|\Psi \rangle = \sum_n c_n |\psi_n\rangle,
$$
where $\hat{H} |\psi_n \rangle = E_n |\psi_n \rangle $, and ${|\psi_n\rangle}$ are a set of orthonormal vectors (meaning that $\langle \psi_k | \psi_n \rangle = \delta_{kn}$). It therefore follows that,
$$
\langle \Psi | \hat{H} | \Psi \rangle = \langle \Psi | \hat{H} \sum_n c_n |\psi_n\rangle = \sum_n c_n E_n \langle \Psi | \psi_n \rangle.
$$
We also take note that,
$$
\langle \psi_k | \Psi \rangle = \langle \psi_k | \sum_n c_n | \psi_n \rangle = \sum_n c_n \delta_{kn} = c_k 
$$
Hence,
$$
\sum_n c_n E_n \langle \Psi | \psi_n \rangle = \sum_n \langle \psi_n | \Psi \rangle E_n \langle \Psi | \psi_n \rangle = \sum_n E_n |\langle \psi_n | \Psi \rangle|^2
$$
From here, it's rather straightforward to use the position basis representation of our $|\Psi\rangle$ and $|\psi_n \rangle$ vectors (shown below) to compute what you're trying to prove.
$$
|\Psi\rangle = \int dx \langle x | \Psi \rangle |x\rangle = \int dx \Psi(x) |x\rangle
$$
A: What I will be describing here applies as a general rule, which automatically solves your problem in particular too.
Let me first remind you about these two concepts to make sure that they are clear and distinct. Postulate IV: the probability to measure an eigenvalue $a$ (with corresponding normalized eigenfunction $u_a$) of an observable $A$ in a system described by a wave function $\psi$ is given by: $$P(a,t)=|⟨u_a|\psi⟩|²$$
This can be seen as a projection of a specific function $u_a$ onto the total function $\psi$ via the scalar product (whereas $\theta$ is the angle between those two) $u_a\psi\cos{\theta}=⟨u_a|\psi⟩$ followed by squaring to get the probability $|⟨u_a|\psi⟩|²=P(a,t)$ which is used in the following concept.
Now the second concept is:$$⟨A⟩_ψ=\Sigma_a P(a)a$$
To be more exhaustive $⟨A⟩_ψ$  is the statistical mean (of a large enough number of measures) conducted on a specific observable $A$ with different possible results $a$ each having their respective probability $P(a)$. Now let's prove the above mentioned equation.
$$⟨A⟩_ψ=⟨\psi|A|\psi⟩\\⟨A⟩_ψ=\int dr \psi^* A \space \psi$$
Knowing that the eigenfunctions $u_a$ of the observable $A$ form a basis on which $\psi$ could be developped as $\psi(\vec r)=\Sigma_a C_a u_a(\vec r)$. Since $C_a$ could be seen as the Fourier coefficient $C_a=\int u_a^*\psi dr=⟨u_a|\psi⟩$ and using the above mentioned concept $P(a)=|⟨u_a|\psi⟩|²=|C_a|²$
$$⟨A⟩_ψ=\int dr\Sigma_aC_au_aA\Sigma_{a'}C^{'}_{a}u_a^{'}$$
$$⟨A⟩_ψ=\Sigma_a\Sigma_{a'}C_aC^{'}_{a}\int u_aAu_a^{'}dr$$
$$⟨A⟩_ψ=\Sigma_{aa'}C_aC^{'}_{a}a'\int u_au_a^{'}dr$$
Since the eigenfunctions $u_a$ are orthonormal $\int u_au_a^{'}dr=\delta{aa'}=\begin{cases}1,\text{if }a=a'\\0,\text{else}\end{cases}$
$$⟨A⟩_ψ=\Sigma_{aa'}C_aC^{'}_{a}a'\delta{aa'}$$
$$⟨A⟩_ψ=\Sigma_{a}|C_a|²a$$
$$⟨A⟩_ψ=\Sigma_{a}P(a)a$$
