# Proper handling of change of units in numerical calculations

Let's say I want to calculate the energy spectrum of Heisenberg model:

$$H = J \sum \limits_{\langle i,j \rangle} \vec S_i \cdot \vec S_j -g ~\mu_B \sum \limits_{i} \vec S_i \cdot \vec B$$

but value of $$J$$ is given as $$J/k_B= 20 ~K$$ (kelvin). now If I put $$J= 20 * 1.38* 10^{−23}$$ joule in $$H$$ and find the energy eigenvalues numerically by diagonalizing , then I may not get correct results because of such a low $$J$$.

Can I do it in following way:

By Converting H in kelvin unit: Keeping J as 20 K and $$\mu_B = 0.671 ~ K ~T^{-1}$$ and B in $$T$$ ($$T$$ =Tesla). then Calculated Energy will be in $$K$$ unit, next I can convert it back to joule or eV.

Am I correct or any better way ?

You're correct, but there's also an easier way. I tend to rephrase such problems in terms of an overall energy scale and a ratio, e.g. $$H=J\left[ \sum \limits_{\langle i,j \rangle} \vec S_i \cdot \vec S_j -\frac{g ~\mu_B}{J} \sum \limits_{i} \vec S_i \cdot \vec B \right] = J\left[ \sum \limits_{\langle i,j \rangle} \vec S_i \cdot \vec S_j -\alpha \sum \limits_{i} \vec S_i \cdot \vec B \right]$$ Then I usually set $$J=1$$ in the numerical calculations (that is, solve the dimensionless Hamiltonian inside the square brackets), and only worry about converting back afterwards. And converting to whatever units of $$J$$ you prefer is easy, since it's just a multiplicative factor.
This approach also has the benefit of making it easy to directly compare one's results with already published literature. Many papers on model Hamiltonians are about the Hamiltonian itself, not some experimental system, and so they present data either in units where $$J=1$$ or in units of $$\epsilon/J$$.