Estimating the heat capacity of ising model I am have written a Metropolis-Hastings algorithm and am currently trying to compare it to the analytical results for the 2D Ising model. The free energy seems reasonable but the heat capacity I'm getting is way off.
I am using the equation $C_{v}=\frac{\beta}{T}[\left<E^{2}\right>-\left<E\right>^{2}]$. Using $\beta=1$ would imply that $T$ is on the order of $10^{23}$ so the prefactor becomes really small. My understanding was that the variance in the energy will be humongous at such high temperatures but my variance is not that large. I think it is because I am using a $16\times16$ lattice and the variance on a finite system (I'm guessing) is bounded. But the computation time is already really slow (5 minutes for $10^{6}$ iterations of Monte Carlo).
I have tried using $C_{v}=-\beta^{2}\frac{\partial^{2} f}{\partial \beta^{2}}$ with a numerical approximation for the second derivative. But my free energy values are also numerically calculated so I sometimes get nonsensical results like negative heat capacity. I was wondering if there are other ways of estimating the heat capacity. Or if I'm stuck with using the variance of the energy, how large a lattice do I need to have?
 A: Above the critical temperature, the variance of the energy diverges like the number $N$ of spins in your system. It would be far more relevant to estimate the specific heat $C_v/N$, for which one has an exact expression in the thermodynamic limit (see Chapter 5 of McCoy and Wu's book or this page).
More precisely, I would suggest that you measure directly the variance of the energy or, better, of the energy density $H/N$ (where $H$ is the Hamiltonian).
The latter can then be compared with the exact solution since $\operatorname{Var}_\beta(H/N) = \frac{d^2}{d\beta^2} \frac{1}{N}\log Z_{N,\beta}$, where $Z_{N,\beta} = \sum_\sigma e^{-\beta H(\sigma)}$ is the partition function, and Onsager's explicit expression for the thermodynamic limit of $\frac{1}{N}\log Z_{N,\beta}$ is given in the links above.
I am also very surprised with the poor computation times you mention.
I would strongly suggest that you use, for instance, c rather than python, as this will allow you to consider much larger systems and, for such simple programs, is not more difficult to implement.
