# Energy of classical ideal gas in the grand canonical ensemble

The canonical partition function for an ideal gas is $$Z(N,V,\beta) = \frac{1}{N!} \left(\frac{V}{\lambda^3}\right)^N$$ where $$\lambda = \sqrt{\frac{\beta h^2}{2 \pi m}}$$ is the thermal De-Broglie wavelength. It is straightforward to obtain $$\langle E \rangle = -\frac{\partial \log Z}{\partial \beta} = \frac{3}{2} N k_B T .$$

From $$Z$$ the grand-canonical partition function is

$$Q(\mu,V,\beta) = \sum_{N=0}^\infty \frac{1}{N!} \left(\frac{e^{\beta \mu} V}{\lambda^3}\right)^N = e^{\frac{e^{\beta \mu} V}{\lambda^3}} .$$

The average particle number is

$$\langle N \rangle = \frac{\partial \log Q}{\partial (\beta \mu)} = \frac{e^{\beta \mu} V}{\lambda^3} .$$

To get the average energy we should do, substituting $$\langle N \rangle$$,

$$\langle E \rangle = - \frac{\partial \log Q}{\partial \beta} = \frac{3}{2} \langle N \rangle k_B T$$

but this is true only if we magically ignore the $$e^{\beta \mu}$$ factor when taking the derivative, otherwise there is an extra (nonsensical) term. I've checked a few sources and this is the accepted solution (after all, it must be this one to be consistent with the canonical ensemble result), although they mysteriously gloss over the issue, so I'm missing something. Thanks.

Hint: You have an error in your computations. In particular in the grand canonical ensemble,

\begin{align} \langle E \rangle \neq -\frac{\partial \log Q}{\partial \beta}. \end{align}

Moreover, I just did the whole computation having corrected this error in the appropriate way, and it worked out the way it should.

Addendum, 2019-02-02. Details Beyond the Hint

Step 1. Recall the following definitions of the grand canonical partition function $$Q$$, the ensemble average energy $$\langle E\rangle$$ in the grand canonical ensemble, and the ensemble average particle number $$\langle N\rangle$$ in the grand canonical ensemble. All sums are over states $$i$$ of the system: \begin{align} Q \equiv \sum_ie^{-\beta(E_i - \mu N_i)}, \qquad \langle E\rangle \equiv \sum_i \frac{e^{-\beta(E_i - \mu N_i)}}{Q}E_i, \qquad \langle N\rangle \equiv \sum_i \frac{e^{-\beta(E_i - \mu N_i)}}{Q}N_i \end{align}

Step 2. Show that the following identity follows from the definitions in Step 1:

\begin{align} \langle E\rangle = -\frac{\partial \ln Q}{\partial \beta} + \mu\langle N\rangle. \end{align}

Step 3. Show that if we take \begin{align} Q = V\frac{e^{\beta\mu}}{\lambda^3}, \end{align} then

\begin{align} -\frac{\partial \ln Q}{\partial \beta} = \frac{3}{2}\frac{\langle N\rangle}{\beta} - \mu\langle N\rangle. \end{align}

Step 4. Combine steps 2 and 3 to obtain the desired result.

• Sorry, but I don't think a hint should be posted as an answer. I think you should add more contents. – FGSUZ Feb 2 '19 at 21:20
• @FGSUZ Fair enough. I included some elaboration. – joshphysics Feb 2 '19 at 22:28
• Statements on partial derivatives without indicating explicitly which variables are kept fixed allow to derive everything of its opposite, in this context. – GiorgioP Feb 5 '19 at 17:52

Yes, there is a subtle issue. Recall the general problem, from which those formulae are derived.

An example first. Thermodynamics say that

$$U=\Phi+TS+\mu N$$

($$\Phi$$ is the grand-canonical potential)

from which you could obtain

$$S=\left( -\frac{\partial \Phi}{\partial T} \right)_{V,\mu}$$

And check that, in thermodynamics, we always indicate a dubindex in the derivatives. That subindex $$(V,\mu)$$, is reminding us that those variables must be kept constsant.

If you think about it, they shoudln't be neccesary, because a partial derivative already assumes implicitly that "all other variables" are kept constant. But thermodynamics can become quite messy, so it is actually really important to keep track on the variables that are kept constant.

Now, if you get this, let's get to the point. When dealing with ensembles, we use the entropic representation. That is working with $$S$$ as fundamental relation, instead of $$U$$. Consequently, you must rearrange the expression:

$$S=-\frac{\Phi}{T} + \frac{U}{T} + \frac{\mu \bar{N}}{T}$$

And now, variables are obtained as always:

$$U=\frac{\partial \Phi}{\partial (\lambda_U)}$$

where $$\lambda_U$$ is the intensive variable associated with $$U$$, which is $$(1/T)$$. So basically you have to calculate:

$$U=\frac{\partial \Phi}{\partial (1/T)}$$

But this partial derivative must be done maintaining the other variables constant. That includes maintaining constant $$(\mu/T)$$

Yes, it is weird: $$1/T$$ varies, but $$\mu/T$$ must not vary. That's the thing.

... and since $$\Phi=-k_B T \ln {(Q)}$$

$$U=\frac{\partial [-k_B\ln{(Q)}]}{\partial (1/T)}$$

And dividing everything by $$k_B$$, you get

$$U=\frac{\partial [-\ln{(Q)}]}{\partial [1/(k_BT)])}=-\frac{\partial \ln{(Q)}}{\partial \beta}$$

But this derivative is done maintaining $$(\mu/T$$) constant. If that is constant, dividing by $$k_B$$ will keep being constant, and hence we write

$$U=-\left(\frac{\partial \ln{(Q)}}{\partial \beta}\right)_{(\beta\mu)}$$

That is, the derivative must be done maintaining $$\beta\mu$$ constant. That's the explanation of your calculus.

There are interesting articles on the lack of rigour of this notation haha.

The expression you chose for $$\left$$ is not consistent with a temperature-independent chemical potential!

To find its dependence, recall that the constants like $$\beta$$ arise from solving the stationary points of the entropy functional:

$$S = -\int \mathrm{d} \Gamma \rho(Q,P) \ln{ \left( \rho \left(Q,P \right) \right) }$$ subject to various conditions, which give rise to Lagrange multipliers, that are later identified with various thermodynamic properties:

• $$\lambda = -\ln{(Z_G)}-1$$ from normalization constraint;

• $$\beta := T^{-1}$$ from constant $$\left ;$$

• $$\gamma := -\mu\beta$$ from constant $$\left ;$$

where $$Z_G = \sum_{N=0}^\infty \int \mathrm{d} \Gamma_N e^{-H\beta -\gamma N}$$

It is now clear that the fugacity $$e^{\mu\beta} = e^{-\gamma}$$ is truly independent of $$\beta$$.

Now the expectation value of energy is given by

$$-\frac{\partial(\ln Z)}{\partial\beta}$$ with the understanding that $$\gamma$$ is constant. This is the same as the formula for the canonical ensemble.

However, the usual treatment is to treat $$\gamma$$ as the dependent variable and $$\mu$$ as independent, since $$\mu$$ has a more obvious physical interpretation.

Therefore the average energy is

\begin{align} \left & ~=~ \frac{1}{Z_G}\sum_{N=0}^\infty \int \mathrm{d} \Gamma_N H e^{-H\beta + \beta\mu N} \\[5px] & ~=~ \frac{1}{Z_G}\sum_{N=0}^\infty \int \mathrm{d} \Gamma_N \left(-\frac{\partial}{\partial\beta} + \mu N \right) e^{-H\beta + \beta\mu} \\[5px] & ~=~ \mu \left - \frac{\partial}{\partial\beta}\left(\ln{Z_G}\right) \end{align} where the partial derivative holds $$\mu$$ constant.

So depending on whether you choose to hold $$\gamma$$ or chemical potential as your independent constant, you get a different formula for $$\left .$$ The end result of your calculation should be independent of this choice, as long as you are consistent with all your derivations.

This explains the "magic" in ignoring the $$e^{\beta\mu}$$ factor. Holding its argument constant is consistent with your expression for $$\left.$$ The "correct" (conventional) Grand canonical ensemble expression contains a term that exactly cancels the "extra (nonsensical) term".

You may take derivative by assuming constant fugacity i.e $e^{\beta\mu}$. Because the Main formula for calculation of partition function in grand canonical ensemble is $Q=\sum\,e^{-\beta(E-\mu N)}$. So when you want calculate mean Energy or $\langle E\rangle =\sum p_i E_i =\sum\frac{e^{-\beta(E_i-\mu N_i)}}{Q}E_i$. We know that $p_i=\frac{e^{-\beta(E_i-\mu N_i)}}{Q}$. so you should take derivative of $\hbox{ln}(Q)$ in a way that for each term just $E_i$ come beside $p_i$ it mean you should take derivative in constant fugacity or constant $e^{\beta\mu}$