The energy of a quantum harmonic oscillator is given by: $$E(n)=\hbar\omega\left(n+\frac{1}{2}\right)$$
The canonical partition function is given by: $$Z(T)=\sum_{n=o}^\infty e^{-\beta E(n)}=\sum_{n=o}^\infty e^{\frac{-\beta \hbar\omega}{2}} e^{-\beta\hbar\omega n}=\sum_{n=o}^\infty e^\frac{-\beta \hbar\omega}{2} \left(e^{-\beta\hbar\omega}\right)^n=\sum_{n=o}^\infty \frac{e^{\frac{-\beta \hbar\omega}{2}}}{1-e^{-\beta\hbar\omega}}$$
The mean energy is given by $$U(T)=\left\langle E \right\rangle=\frac{1}{Z}\sum_{n=o}^\infty E(n) e^{-\beta E(n)}$$
The professor (Solid State Physics) asked us to calculate the mean energy.
For me the $Z$ and the $e^{-\beta E(n)}$ terms cancel each other, which leaves us only with $\sum_{n=o}^\infty E(n)$ which for me is equal to: $$\sum_{n=o}^\infty E(n)= \hbar\omega\left(\frac{1}{2}+\left\langle n \right\rangle\right) $$
The professor got to the same result but he wrote on the board: $$U(T)=\frac{\hbar\omega}{2}+\frac{\hbar\omega e^{-\beta\hbar\omega}}{1-e^{-\beta\hbar\omega}}=\hbar\omega\left(\frac{1}{2}+\left\langle n \right\rangle\right)$$
I would like to know where the $\frac{e^{-\beta\hbar\omega}}{1-e^{-\beta\hbar\omega}}$ term is coming from
Thanks
They do not cancel, because you can't factor the nonconstant $E(n)$ term out of the sum in order to make them cancel. For a basic illustration of this, consider $E(1)=1,F(1)=2,E(2)=2,F(2)=1$. Then
$$\frac{\sum_{n=1}^2 E(n) F(n)}{\sum_{n=1}^2 F(n)} = \frac{2 + 2}{2 + 1} = \frac{4}{3} \neq \sum_{n=1}^2 E(n)=3.$$
At any rate, you also calculated $\sum_{n=0}^\infty E(n)$ incorrectly; this sum is $\infty$.
Instead you have to actually calculate the sum in the numerator. One nice trick for this is differentiation term by term. Consider
$$\sum_{n=0}^\infty x^n = \frac{1}{1-x}$$
where $|x|<1$. Because of absolute convergence, you can differentiate this on both sides, differentiating the left side term-by-term, to get
$$\sum_{n=1}^\infty n x^{n-1} = \frac{1}{(1-x)^2}.$$
With some minor tweaking you can use that to evaluate the sum in your numerator.
You can get your expression involving $\langle n \rangle$ by splitting up your sum; the $\langle n \rangle$ comes from $\frac{\sum_{n=0}^\infty n B(n)}{\sum_{n=0}^\infty B(n)}$ (where $B(n)$ is the Boltzmann factor), not from $\sum_{n=0}^\infty n$ (which is $\infty$, as is $\sum_{n=0}^\infty E(n)$).