How do I calculate the probability that the oscillator is in a certain state using partition function? So let's say I have a single ($N=1$) quantum harmonic oscillator and the energy is determined by $E_n = (n + 1/2) \cdot \hbar  \omega$ (where $n$ is the quantum number and $n$ = $0, 1, 2, \ldots$)
What's the probability that the oscillator is in the state labeled $n$ at temperature $T$?
So according to my calculation, $Z$, the partition function, is
$Z = 1 / (1 - x)$ where $x = e^{-\beta \hbar \omega} \Rightarrow P = x ^ n  (1 - x)$.
Is it correct?
Also, how do I go about calculating the probability of finding the oscillator in a state with odd quantum number?
 A: Your calculation looks fine to me (technically, your partition function should have an extra factor of $e^{-\frac 12 \beta\hbar\omega}$, but this is unimportant, as it cancels in all observables).
Edit: As in the comment by abcXYZ, the probability of finding the system in a state corresponding to any odd value of $n$ is
$$
P(n~\text{is odd}) = (1-x)(x + x^3 + \ldots + x^{2k-1} + \ldots) = \frac{(1-x)x}{1-x^2} = \frac{x}{1+x}
$$
where $x = e^{-\beta\hbar\omega}$.  To give some confidence that this is indeed the right answer, we can check some limits:


*

*At $T=0$, we expect that oscillator to be in its ground state, and therefore $n$ cannot be odd.  $T=0$ corresponds to $\beta = \infty$, and therefore $x=0$, which indeed gives $P=0$ in our formula.

*As $T \to \infty$, we expect the oscillator to spread out over all energy eigenstates, and therefore the probabilities of $n$ being odd or even to be equal.  And indeed, $T \to \infty$ corresponds to $x \to 1$, for which our formula gives $P \to \frac 12$.


It's a good habit to do these sorts of simple checks on any formulae you derive.
A: Given your partition function, you can use a heuristic approach like in the other answer, but if you want to calculate it, then you want to construct the density operator $\rho$ for your system and then find probabilities via
$$ \mathcal{P}_n = Tr(\rho P_n)$$
where $P_n$ is the projection operator of the $n^{th}$ pure state. 
This is a very similar question I recently answered. Here's a nice intro to quantum stat phys which details the properties of $\rho$. The last page of this article shows how to analytically derive the partition function.
