The expectation value of a quantum-mechanical operator \(\hat{O}\) is the weighted average value of its observable. It is defined as:
$$\langle O\rangle=\langle\psi\vert\hat{O}\vert\psi\rangle\; \; \; \; \; \; \; \; \; \; \; 34$$

The above equation has roots in probability theory, where the expectation value or expected value of an observable \(O\) is \(\langle O\rangle=\sum_{i=1}^{N}p_io_i\), with \(p_i\) being the probability of observing the outcome \(o_i\).
$$\langle O\rangle=\sum_{i=1}^{N}p_io_i=\sum_{i=1}^{N}\left | \langle\phi_i\vert\psi \rangle\right |^{2}o_i=\sum_{i=1}^{N} \langle\phi_i\vert\psi \rangle^{*}\langle\phi_i\vert\psi \rangle o_i$$
$$=\sum_{i=1}^{N} \langle\psi\vert\phi_i \rangle\langle\phi_i\vert\psi \rangle o_i=\langle\psi\vert(\sum_{i=1}^{N}o_i\vert\phi_i \rangle\langle\phi_i)\vert\psi \rangle$$
From eq30, \(\hat{O}=\sum_{i=1}^{N}o_i\vert\phi_i \rangle\langle\phi_i\vert\), and so
$$\langle O\rangle=\langle\psi\vert\hat{O}\vert\psi \rangle$$
We further postulate that eq34 is valid for an infinite dimensional Hilbert space.

Question
Why is \(p_i=\vert\langle\phi_i\vert\psi\rangle\vert^{2}\) ?
Answer
Consider an operator with a complete set of orthonormal basis eigenfunctions \(\left \{ \phi_i \right \}\). So, any eigenfunction \(\psi\) can be written as a linear combination of these basis eigenfunctions, i.e. \(\psi=\sum_{i=1}^{N}c_i\phi_i\). According to the Born rule, the probability that a measurement will yield a given result is \(\vert\psi\vert^{2}=\psi^{*}\psi\), where \(\int\psi^{*}\psi\: d \tau=1\). So,
$$\int\psi^{*}\psi\: d \tau=\int \sum_{i=1}^{N}c_{i}^{*}\phi_{i}^{*}\sum_{i=1}^{N}c_{i}\phi_{i}d\tau=\sum_{i=1}^{N}\vert c_{i}\vert^{2}\int \phi_{i}^{*}\phi_i d\tau=\sum_{i=1}^{N}\vert c_{i}\vert^{2}=1$$
We have used the orthonormal property of in the 2nd and 3rd equalities. \(\vert c_i\vert^2\) is interpreted as the probability that a measurement of a system will yield an eigenvalue associated with the eigenfunction . Therefore,
$$\vert\langle\phi_i\vert\psi\rangle\vert^{2}=\vert\langle\phi_i\vert\sum_j c_j\phi_j\rangle\vert^{2}=\vert\langle\phi_i\vert\ c_i\phi_i\rangle\vert^{2}=\vert c_i\vert^{2}$$

Question
Using the Schrodinger equation, show that the expectation value of the Hamiltonian is \(E=\int \psi_i^{*}\hat{H}\psi_i\: d\tau\).
Answer
Multiplying both sides of eq40 on the left by \(\psi_i^{*}\) and integrating over all space, we have
$$E=\frac{\int \psi_i^{*}\hat{H}\psi_i\: d\tau}{\int \psi_i^{*}\psi_i\: d\tau}$$
If the wavefunction is normalised, the above equation becomes \(E=\int \psi_i^{*}\hat{H}\psi_i\: d\tau\).