When the batteries are in series, the total resistance is the sum of their internal resistances. When they are in parallel, the effective resistance is reduced. By applying the formula for heat produced, $P = \frac{V^2}{R}$, and using the given condition $P_1 = 2P_2$, we can calculate that $R = 5 \, \Omega$.