Calculating the probability of a given energy Given a normalised wavefunction say $$\psi(x) = A\sin(n\pi x),$$ (where $A$ is a normalisation constant) I can calculate the probability of finding the particle being between a position $x$ and $x + dx$ as $$\int_{x}^{x+dx} \psi(x)^*\psi(x) dx.$$ Likewise I can calculate the expected value of the energy $$\langle E \rangle = \int_{-\infty}^\infty \psi(x)^*\hat{H} \psi(x) dx.$$ However, how can I calculate the probability of a given value of the energy say $$E = \frac{\hbar^2 \pi^2}{2}$$ as my wavefunction $\psi(x)$ is defined in terms of position not energy?
 A: $\newcommand{\d}{\;\mathrm{d}}$
Elaborating on the answer of zeldredge, I want to say why the following expression works:
$$P(E_0) = \left| \int_{-\infty}^{\infty}  \ \Phi^* \psi \d x \right|^2 \tag{1}$$ 
Notice that the eigenfunctions of the Hamiltonian spans the space. That is you can write any function $\psi$ as a linear combination of eigenfunctions of the Hamiltonian ie.
$$\psi=a_0\Phi_0+a_1\Phi_1+a_2\Phi_2  \dots  = \sum_i a_i \Phi_i \tag{2}$$
with  $a_i \in \mathbb C$  and $\sum_i \left|a_i \right|^2=1$. Notice that as in all superposition of states the probability of finding particle in a particular state is given by $\left| a_i \right|^2$. Assuming that you have chosen your states cleverly such that they are orthonormal ie they satisfy the following property,
$$\int \Phi_i^*\Phi_j \d x = \delta_{ij}$$  
you can see immediately why Eqn. (1) works.
$$\int \Phi_i^* \psi \d x = \int \Phi_i^* \sum_j a_j \Phi_j \d x = \sum_j a_j\int \Phi_i^* \Phi_j \d x = \sum_j \delta_{ij} a_j =a_i $$
Therefore the norm squared of this expression just gives the probability to find the state in the energy eigenfunction $\Phi_i$.
Notice I assumed that the energy levels are discrete to write the equation (2). Furthermore I dropped $x$'s in $\psi(x)$ and $\Phi(x)$ because they were cluttering the equations.
A: You have to know the energy eigenstates. Suppose you know that $\Phi (x)$ is an energy eigenstate with $E = E_0$. Then the probability that your state $\psi(x)$ will be measured to have energy $E_0$ is:
$$
P(E_0) = \int_{-\infty}^{\infty} \mathrm{d} x \ \Phi^*(x) \psi(x)
$$
You can do this for the full set of eigenstates $\Phi_i$ to get the wavefunction in an energy basis (instead of the position basis you have it represented in now). Note you can't always do this for an arbitrary $E$, because only a subset of them (the eigenvalues) are going to be energy eigenstates, although for some systems (scattering states) you have a continuous basis for energy.
EDIT: Another thing I forgot to add is that your energy states may be degenerate--there might be multiply $\Phi$ that could give you $E_0$. In that case you need to add up the different probabilities from each one.
A: First you have to find the eigenstate of the Hamiltonian, in other words, you have to solve the equation: $$\hat H \psi_{E}(x)=E \psi_{E}(x)，$$ then the inner product squared of $$\psi_{E}(x)\quad and \quad \psi(x)$$ is the probability you want.
