You have various places with expressions like
(Ibarhc/Hbar)
where the denominator is 0, resulting in NaN.