# Ideal gas law for a gas with nonuniform temperature

Consider a piston-cylinder assembly with an axial temperature distribution $T(x)$ in the gas.

The entire system, however, has a uniform pressure. Can I still apply the ideal gas law $PV = nRT(x)$?

If you have such a system, then, assuming the pressure P is uniform, you can calculate the local molar volume as $v(x)=\frac{RT(x)}{P}$. The total number of moles of gas in the cylinder is: $$n=A\int_0^L{\frac{dx}{v(x)}}=\frac{PA}{R}\int_0^L{\frac{dx}{T(x)}}\tag{1}$$If we call $\bar{T}$ the "effective average temperature," we can also write $$n=\frac{PV}{R\bar{T}}=\frac{PAL}{R\bar{T}}\tag{2}$$Combining Eqns. 1 and 2, we obtain:$$\frac{1}{\bar{T}}=\frac{1}{L}\int_0^L{\frac{dx}{T(x)}}\tag{3}$$From this we see that the effective average temperature (for use with the ideal gas law) is equal to the harmonic mean of the temperature variation over the length of the cylinder.