Derivation of formula for heat produced