Need verification for the entropy equation in statistical thermodynamics The relationship between entropy $S$, the total number of particles $N$, the available energy levels $E_j$ and a yet to be defined parameter $\beta$ is:
$$S(\beta)=k_B \cdot N \cdot \ln\bigg(\sum_{j=1}^n[e^{\beta E_j}]\bigg) - k_B\cdot \beta \sum_{j=1}^n\bigg[\frac{N}{\sum_{i=1}^n [e^{\beta E_i}]}\cdot e^{\beta E_j}\cdot E_j\bigg]$$
The partition function $Z$ and the total energy $U$ as functions of $\beta$ are:
$$\sum_{j=1}^n[e^{\beta E_j}] = Z(\beta) \tag{1}$$
$$\sum_{j=1}^n\bigg[\frac{N}{\sum_{i=1}^n [e^{\beta E_i}]}\cdot e^{\beta E_j}\cdot E_j\bigg]=U(\beta) \tag{2}$$
I need to first derive $\frac{dS}{d\beta}$ and then substitute parameters within $\frac{dS}{d\beta}$ with $\frac{dZ}{d\beta}$ and $\frac{dU}{d\beta}$ if there are any. I came up with the following:
$$\frac{dS}{d\beta}=k_B\cdot \beta \cdot \bigg(\frac{d\big(\ln(Z)\big)}{d\beta}\cdot U - \frac{dU}{d\beta}\bigg)$$
However, I am not sure if this derivation is correct and would really appreciate a verification on this.
 A: $$S(\beta) = k_B \cdot N \cdot \ln(Z(\beta)) - k_B\cdot \beta \cdot U(\beta).$$
$$U(\beta) = \sum_{j=1}^n\bigg[\frac{N}{\sum_{i=1}^n [e^{\beta E_i}]}\cdot e^{\beta E_j}\cdot E_j\bigg] = \frac{N}{\sum_{i=1}^n [e^{\beta E_i}]}\,\sum_{j=0}^{n} e^{\beta\,E_j}\cdot E_j = \frac{N}{Z(\beta)} \sum_{j=0}^{n} e^{\beta\,E_j}\cdot E_j$$
$$\frac{dZ}{d\beta} = \sum_{j=0}^{n} e^{\beta\,E_j}\cdot E_j = \frac{U(\beta)\cdot Z(\beta)}{N}$$
$$\frac{dS}{d\beta}=k_B\cdot \left( N\cdot\frac{d\left(\ln(Z)\right)}{d\beta} - U - \beta \cdot \frac{dU}{d\beta}\right)$$
$$\frac{dS}{d\beta}=k_B\cdot \left( \frac{N}{Z}\cdot\frac{dZ}{d\beta}-U-\beta\cdot\frac{dU}{d\beta} \right)$$
$$\frac{dS}{d\beta}= k_B\cdot \left( \frac{N}{Z}\cdot\frac{U\cdot Z}{N}-U-\beta\cdot\frac{dU}{d\beta} \right) = -\beta\cdot k_B\cdot \frac{dU}{d\beta}$$
Your first term vanished somewhere in my solution. I cannot tell where either of us did a mistake without comparing solutions.

Part II
Counting in degeneracy:
$$S=k_B\bigg(N \cdot \ln(Z(\beta)) - \beta U(\beta) + \ln(\frac{N}{Z(\beta)}) \cdot N - \frac{N^2}{Z(\beta)}\bigg)$$
which has the last two terms in addition to the non-degenerate solution. So let's just solve for these two (using the fact that $\ln(a/b)=\ln(a)-\ln(b)$):
$$\frac{d}{d\beta}\left( k_B\cdot\left[ N \cdot \ln(\frac{N}{Z(\beta)}) - \frac{N^2}{Z(\beta)} \right] \right) = k_B\cdot\left(
- N \cdot\frac{1}{Z}\frac{dZ}{d\beta}
+ \frac{N^2}{Z^2}\cdot\frac{dZ}{d\beta}
\right)$$
$$ = k_B \cdot\frac{dZ}{d\beta}\cdot\frac{N}{Z}\cdot\left( \frac{N}{Z} - 1 \right) = k_B \cdot\frac{U\cdot Z}{N}\cdot\frac{N}{Z}\cdot\left( \frac{N}{Z} - 1 \right) $$
$$ = k_B \cdot U(\beta) \cdot\left( \frac{N}{Z(\beta)} - 1 \right) $$
Therefore, overall derivative considering degeneracy is:
$$\frac{dS}{d\beta} = k_B\cdot\left( - \beta\cdot\frac{dU}{d\beta} + \frac{U(\beta)\cdot N}{Z(\beta)} - U(\beta) \right)$$
So, no, unless you have a partition function of constant value $N$, factoring in degeneracy changes the outcome.
